Skip to content
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

Merged
merged 1 commit into from
Apr 11, 2022

Conversation

waiting-for-dev
Copy link
Contributor

@waiting-for-dev waiting-for-dev commented Mar 28, 2022

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 (example rotate: 90). In the long run, we should aim to completely
differentiate how definitions are given for each library.

Needs to be backported.

Checklist:

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have updated Guides and README accordingly to this change (if needed)
  • I have added tests to cover this change (if needed)
  • I have attached screenshots to this PR for visual changes (if needed)

@waiting-for-dev waiting-for-dev mentioned this pull request Mar 28, 2022
14 tasks
@waiting-for-dev waiting-for-dev force-pushed the waiting-for-dev/active_storage_size branch from 09b0107 to 12e80cf Compare March 28, 2022 05:02
@waiting-for-dev waiting-for-dev force-pushed the waiting-for-dev/libvips branch from f13ddba to a502886 Compare March 28, 2022 09:03
@waiting-for-dev waiting-for-dev force-pushed the waiting-for-dev/active_storage_size branch from 12e80cf to 11a12f6 Compare March 28, 2022 09:04
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense

attr_reader :decorated_attachment

def initialize(decorated_attachment, styles: {})
@decorated_attachment = decorated_attachment
Copy link
Member

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?

Copy link
Contributor Author

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.

Base automatically changed from waiting-for-dev/libvips to master March 31, 2022 11:36
@waiting-for-dev waiting-for-dev force-pushed the waiting-for-dev/active_storage_size branch from 11a12f6 to 1284caf Compare April 1, 2022 03:47
Copy link
Member

@spaghetticode spaghetticode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Marc 🎉

Copy link
Member

@tvdeyen tvdeyen left a 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 :^
Copy link
Member

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

Suggested change
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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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 }
Copy link
Member

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.

Copy link
Contributor Author

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.
@waiting-for-dev waiting-for-dev force-pushed the waiting-for-dev/active_storage_size branch from 1284caf to b231ddd Compare April 5, 2022 11:25
@waiting-for-dev waiting-for-dev merged commit 6c79f34 into master Apr 11, 2022
@waiting-for-dev waiting-for-dev deleted the waiting-for-dev/active_storage_size branch April 11, 2022 04:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants