-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
recreate_versions! is changing the original file content #2480
Comments
@feliperaul But I was able to get around the issue using common sense: My fix was to move all Regarding your example, it would be something like this: ...
def cache_dir
"#{Rails.root}/tmp/uploads"
end
version :watermark do
process :fix_exif_rotation
process :set_original_dimensions
process convert: 'jpg'
process resize_to_fill: [1280, 720], if: :is_landscape?
process resize_to_fit: [1280, 720], if: :is_portrait?
process :watermark_image
end
version :mobile do
process :fix_exif_rotation
process :set_original_dimensions
process convert: 'jpg'
process resize_to_fill: [1280, 720], if: :is_landscape?
process resize_to_fit: [1280, 720], if: :is_portrait?
process resize_to_fill: [720, 405], if: :is_landscape?
process resize_to_fit: [720, 405], if: :is_portrait?
end
version :thumb do
process :fix_exif_rotation
process :set_original_dimensions
process convert: 'jpg'
process resize_to_fill: [1280, 720], if: :is_landscape?
process resize_to_fit: [1280, 720], if: :is_portrait?
process resize_to_fill: [470, 265], if: :is_landscape?
process resize_to_fit: [470, 265], if: :is_portrait?
end
# two empty lines here?
def extension_whitelist
... To DRY things up you could use a class method defined before the calls: def self.common_processing
process :fix_exif_rotation
process :set_original_dimensions
process convert: 'jpg'
process resize_to_fill: [1280, 720], if: :is_landscape?
process resize_to_fit: [1280, 720], if: :is_portrait?
end
...
version :watermark do
common_processing
process :watermark_image
end
# etc. Please have a go with this and let us know if it worked for you. In case you still want to process the original file at the upload, an approach I could think of regarding all said before about the Something like this: ...
def cache_dir
"#{Rails.root}/tmp/uploads"
end
process :fix_exif_rotation, if: :just_uploaded?
process :set_original_dimensions, if: :just_uploaded?
process convert: 'jpg', if: :just_uploaded?
process resize_to_fill: [1280, 720], if: :just_uploaded_and_landscape?
process resize_to_fit: [1280, 720], if: :just_uploaded_and_portrait?
version :watermark do
process :watermark_image
end
... |
Hello, @mshibuya, I was wondering if there's a workaround to have the corrected behaviour back. I'm trying to upgrade from a pre 3.0 version of carrierwave and I depend on having a way to re-process the original file. I have an uploader that can rotate existing images by processing it, here is a simplified version of it: class ImageUploader < CarrierWave::Uploader::Base
...
process :process_rotate
...
version :thumb do
# specific version processing here
end
def rotate(degrees)
@degrees = degrees
end
private
def process_rotate
unless @degrees.to_i.zero?
manipulate! do |img|
img.rotate(@degrees.to_i)
end
end
end
end And I use it like this: record.image.rotate(90)
record.recreate_versions! I can't just add the processing method to each version because images need to be able to rotate based on the current rotation state and because the versions are created from the original file (not rotated) it won't work. Is there any way that I can reprocess the original file and its versions? |
I'm on the latest version
2.1.0
.When I invoke
recreate_versions!
, my original version is being re-processed, it's file size is increasing (from 385kb to 451kb) and, of course, it's Sha-256 is changing as well.Coincidently #2479 is also the most recent issue opened, but it only tackles a modification in the original file's modified timestamp, while at this issue I'm pointing that the original file is having it's content changed as well.
Carrierwave has a test for this (https://github.com/carrierwaveuploader/carrierwave/pull/2020/files), but somehow it's not preventing this bug.
I'm pasting my entire uploader below, because maybe it helps with debugging:
The text was updated successfully, but these errors were encountered: