-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fixes defining thumbnail sizes through ActiveStorage adapter #4318
Conversation
09b0107
to
12e80cf
Compare
f13ddba
to
a502886
Compare
12e80cf
to
11a12f6
Compare
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.
makes sense
core/app/models/concerns/spree/active_storage_adapter/attachment.rb
Outdated
Show resolved
Hide resolved
core/app/models/concerns/spree/active_storage_adapter/attachment.rb
Outdated
Show resolved
Hide resolved
attr_reader :decorated_attachment | ||
|
||
def initialize(decorated_attachment, styles: {}) | ||
@decorated_attachment = decorated_attachment |
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.
Not sure how likely it is that this file gets decorated by stores, but should we deprecate the old instance variable name? Or maybe simply keep the old name?
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.
Fair enough. I'm keeping the old name now.
11a12f6
to
1284caf
Compare
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.
Thank you Marc 🎉
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.
Currently working on porting Alchemy from Dragonfly to active storage and I think this needs to be changed.
case definition[-1].to_sym | ||
when :> | ||
{ resize_to_limit: width_height } | ||
when :^ |
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.
This actually has to be
when :^ | |
when :# |
for resize_to_fill
, because it crops the image to fill the space. See https://github.com/janko/image_processing/wiki/Resize-To-Fill
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.
Actually, image_processing
transforms resize_to_fill
into ^
:
See also docs in imagemagick.
Do I get it right?
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.
Yes. I see, this seems to be a Dragonfly thing. Really confusing actually, because Dragonfly just forwards the string to convert -thumbnail
https://markevans.github.io/dragonfly/imagemagick#thumb
when :^ | ||
{ resize_to_fill: width_height } | ||
else | ||
{ resize_to_fit: width_height } |
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.
This is the case for :^
, BUT this upscales the image, if the original dimensions are smaller than the requested dimensions. Not sure if we want that as default? We probably want resize_to_limit
as default.
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.
We probably want resize_to_limit as default.
Thanks, I think you're right, plus it won't change the previous behavior. Fixed.
The adapter intends to make it possible to work with ActiveStorage as it was Paperclip. We had been using Paperclip until Rails 6.1 introduced ActiveStorage's public links. We moved to ActiveStorage as the default file attachment backend from that point on, but we tried to make its API compatible with Paperclip's one. See #3501 for details. When trying to translate [Paperclip's style definitions](https://github.com/solidusio/solidus/blob/564b4fe54648537b6b1420eed5a05cba6854e915/core/lib/spree/app_configuration.rb#L494) (based on [ImageMagick](https://legacy.imagemagick.org/Usage/thumbnails/)) to what ActiveStorage expects (which is [image_processing syntax](https://github.com/janko/image_processing), common for ImageMagick and libvips), we were transforming everything to a [`resize_to_limit`](https://github.com/janko/image_processing/blob/master/doc/minimagick.md#resize_to_limit) option. However, that corresponds to the `>` symbol in ImageMagick, but not to other options that can be given. Whit this commit, we add support for defining other kinds of transformations in ActiveStorage. However, we're still missing more advanced options that can be given when using [standalone Paperclip](https://www.rubydoc.info/gems/kt-paperclip/7.1.1) (example `{ geometry: '100x100', format: :jpg }`) or [standalone ActiveStorage](https://github.com/janko/image_processing/blob/master/doc/minimagick.md#methods) (example `rotate: 90`). In the long run, we should aim to completely differentiate how definitions are given for each library.
1284caf
to
b231ddd
Compare
Description
The adapter intends to make it possible to work with ActiveStorage as it was Paperclip. We had been using Paperclip until Rails 6.1 introduced ActiveStorage's public links. We moved to ActiveStorage as the default file attachment backend from that point on, but we tried to make its API compatible with Paperclip's one. See #3501 for details.
When trying to translate Paperclip's style definitions (based on ImageMagick) to what ActiveStorage expects (which is image_processing syntax, common for ImageMagick and libvips), we were transforming everything to a
resize_to_limit
option. However, that corresponds to the
>
symbol in ImageMagick, but not to other options that can be given.Whit this commit, we add support for defining other kinds of transformations in ActiveStorage. However, we're still missing more
advanced options that can be given when using standalone Paperclip (example
{ geometry: '100x100', format: :jpg }
) or standalone ActiveStorage (examplerotate: 90
). In the long run, we should aim to completelydifferentiate how definitions are given for each library.
Needs to be backported.
Checklist: