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

Mogrify unrecognized option resize-to-fit #39

Closed
wbotelhos opened this Issue May 8, 2018 · 10 comments

Comments

Projects
None yet
6 participants
@wbotelhos
Copy link

wbotelhos commented May 8, 2018

Hi @janko-m ,

First of all, thanks for this great gem! (:

Maybe it is an issue related with ActiveStorage, but I decided to post here, since you are the man of Image Processing that added the macros to ActiveStorage. Sorry if this is not the right place for it.

Error:

`mogrify -resize-to-fit [345, 345] /var/folders/jc/793vxbvx11s61czx9crv26tm0000gn/T/mini_magick20180508-30453-oz88oi.jpg` failed with error: mogrify: unrecognized option `-resize-to-fit' @ error/mogrify.c/MogrifyImageCommand/5909.

I tried to simulate on console, but there I need to call processed to get the same error:

record = School.create!(name: Time.current.to_s)
image  = File.open('spec/support/fixtures/image.jpg')

record.avatar.attach(io: image, filename: 'image.jpg')

variant = record.avatar.variant(resize_to_fit: [10, 10])

Variant result:

=> #<ActiveStorage::Variant:0x00007febf9fac070
 @blob=
  #<ActiveStorage::Blob:0x00007febf9f8bc80
   id: 22,
   key: "1esfQGcWnN1zHnNxJFNe3Fzt",
   filename: "image.jpg",
   content_type: "image/jpeg",
   metadata: {"identified"=>true},
   byte_size: 2310,
   checksum: "LZbH9nXeGPWBxV/I1nXtNw==",
   created_at: Tue, 08 May 2018 13:17:41 -03 -03:00>,
 @variation=#<ActiveStorage::Variation:0x00007febf9fac048 @transformations={:resize_to_fit=>[10, 10]}>>

Now when a call processed, that I think is the same called inside my aplication with image_tag:

[103] pry(main)> variant.processed
  Disk Storage (0.2ms) Checked if file exists at key: variants/1esfQGcWnN1zHnNxJFNe3Fzt/f237c4e4085eba8ff922ab8f00a2c1c658d211aae7b02322a2c642be463731bc (no)
MiniMagick::Error: `mogrify -resize-to-fit [10, 10] /var/folders/jc/793vxbvx11s61czx9crv26tm0000gn/T/mini_magick20180508-30841-1yac7pq.jpg` failed with error:
mogrify: unrecognized option `-resize-to-fit' @ error/mogrify.c/MogrifyImageCommand/5909.
from /Users/wbotelhos/.rvm/gems/ruby-2.5.1@app/gems/mini_magick-4.8.0/lib/mini_magick/shell.rb:17:in `run

Could you, please, help me?
Thank you! <3

@janko

This comment has been minimized.

Copy link
Owner

janko commented May 8, 2018

Active Storage 5.2 still uses MiniMagick directly, so there are no #resize_* macros available there. The ImageProcessing addition to Active Storage was merged after 5.2 was released, so it's currently available only on GitHub and will be released in Active Storage 6.0. The mogrify command indicates that MiniMagick::Image class is used, as ImageProcessing gem uses convert.

@janko janko closed this May 8, 2018

@wbotelhos

This comment has been minimized.

Copy link
Author

wbotelhos commented May 8, 2018

Oh! I was reading your PR and did not realize that it was not released.

Thanks you for your support. <3

@henrik

This comment has been minimized.

Copy link

henrik commented Jun 16, 2018

Came here after accidentally applying the edge Rails guides to non-edge Rails (5.2).

Instead of item.image.variant(resize_to_fit: [ 100, 100 ]), this works with Rails 5.2: item.image.variant(resize: "100x100") (It still resizes to fit; the image won't be forced to square proportions.)

@richardrails

This comment has been minimized.

Copy link

richardrails commented Jun 20, 2018

so how to square the proportions? Any idea?

@richardrails

This comment has been minimized.

Copy link

richardrails commented Jun 20, 2018

it is item.image.variant(resize: "100x100!")

@anthonymidili

This comment has been minimized.

Copy link

anthonymidili commented Jun 30, 2018

richardrails - for now you can use Mogrify directly like this.

image.variant(combine_options: {
      auto_orient: true,
      gravity: "center",
      resize: "100x100^",
      crop: "100x100+0+0"
      })
@wbotelhos

This comment has been minimized.

Copy link
Author

wbotelhos commented Jun 30, 2018

Thanks @anthonymidili ,

I wasn't using the auto_orient: true option nor the 0 + 0 suffix.
What they do?

@janko

This comment has been minimized.

Copy link
Owner

janko commented Jun 30, 2018

Since this discussion is about ActiveStorage 5.2, which doesn't use ImageProcessing, maybe it could be moved to the Rails repo or the Rails Google group 😉

@anthonymidili

This comment has been minimized.

Copy link

anthonymidili commented Aug 6, 2018

Sorry last comment -

auto_orient is done by default by ImageProcessing, but you have to manually set it with Mogrify. I find when uploading images taken with a cell phone, in the portrait position, the image will be displayed in landscape. This operator reads and resets the EXIF image profile setting 'Orientation' and then performs the appropriate 90 degree rotation on the image to orient the image, for correct viewing. ImageMagick - auto-orient

The +0+0 argument in the crop is actually unnecessary, as it is the default. It specifies the offset to use. ImageMagick - Image Geometry

Hope this helps. Happy coding

@equivalent

This comment has been minimized.

Copy link

equivalent commented Jan 23, 2019

@anthonymidili you deserve a cookie ! Your auto_orient suggestion help me solve
rails/rails#35028 (comment)

thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment