image_processing: Mogrify unrecognized option resize-to-fit

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! ❤️

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 10
  • Comments: 15 (2 by maintainers)

Most upvoted comments

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 - for now you can use Mogrify directly like this.

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

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.

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

For those on edge rails like me, make sure you have gem 'image_processing', '~> 1.0' in your Gemfile.

Just to be clear, the ! in item.image.variant(resize: "100x100!") will not CROP the image, instead it will force it into the square aspect ratio, resulting in a distorted image.

At this second I am using

item.image.variant(combine_options: { resize: '100x100^', gravity: 'center', extent: '100x100' })

And that seems to be cropping rectangular images as expected. Also, the arguments are order-sensitive, so don’t try to alphabetize them.

Ok, thanks for that little bit extra information.

@anthonymidili you deserve a cookie ! Your auto_orient suggestion help me solve https://github.com/rails/rails/issues/35028#issuecomment-456869539

thx