-
Notifications
You must be signed in to change notification settings - Fork 8.6k
FIX: key optimized images on format #32575
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
Conversation
Previous to this change when we used to specify format it could get an image in the incorrect format. Also... allows image magick to decode svg --- There remains a bug where the crop / resize information is not stored in optimized images this means that sometimes when asking for a cropped image you may get a resized one.
@@ -49,7 +49,8 @@ def self.create_for(upload, width, height, opts = {}) | |||
end | |||
|
|||
# prefer to look up the thumbnail without grabbing any locks | |||
thumbnail = find_by(upload_id: upload.id, width: width, height: height) | |||
extension = ".#{opts[:format] || upload.extension}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to store the leading .
for every single optimized images? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is "format" to correct name for the option? Why not "extension"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree this needs cleaning up, but I worry about the huge rabbit hole here. The . and calling this format is very confusing.
@@ -49,7 +49,8 @@ def self.create_for(upload, width, height, opts = {}) | |||
end | |||
|
|||
# prefer to look up the thumbnail without grabbing any locks | |||
thumbnail = find_by(upload_id: upload.id, width: width, height: height) | |||
extension = ".#{opts[:format] || upload.extension}" | |||
thumbnail = find_by(upload_id: upload.id, width: width, height: height, extension: extension) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: you can omit the variables when the keys have the same name
thumbnail = find_by(upload_id: upload.id, width: width, height: height, extension: extension) | |
thumbnail = find_by(upload_id: upload.id, width:, height:, extension:) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh til
app/models/optimized_image.rb
Outdated
@@ -93,7 +93,7 @@ def self.create_for(upload, width, height, opts = {}) | |||
opts = opts.merge(quality: target_quality) if target_quality | |||
opts = opts.merge(upload_id: upload.id) | |||
|
|||
if upload.extension == "svg" | |||
if extension == ".svg" && upload.extension == "svg" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think just extension == ".svg"
is enough here? We can't convert any raster images into an SVG anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a good point I guess we should reject earlier...
thanks @ZogStriP |
Previous to this change when we used to specify format it could get an image
in the incorrect format.
Also... allows image magick to decode svg
There remains a bug where the crop / resize information is not stored in optimized images
this means that sometimes when asking for a cropped image you may get a resized one.