Unable to crop image using mini_magick

I use mini_magick as an interface to use ImageMagick to control some image. Size changes perfectly . But when I want to crop the image:

img = MiniMagick::Image.open(url) img.crop('200x800!') 

He constantly asks for No such file

 No such file or directory - /var/folders/c4/mqlwdx_d3kj6hqcnvbjr9mn80000gn/T/mini_magick20120504-11111-16kayc1.png 
+8
minimagick
source share
2 answers

Ah, I searched with the wrong keyword phrase, I think. The correct answer comes to me when I look for minimagick instead of mini_magick . Undefined Cropping Method! Using Carrierwave with a MiniMagick on rails 3.1.3 especially this answer https://stackoverflow.com/a/364829/

I knew that the stuff about mini_magick is just a mogrify wrapper and so on. The reason for my problem is that -crop only accepts fully formatted geometry. so I changed the expression to:

 img.crop('200x800+0+0') 

and it works.

+30
source share

Just in case, if anyone uses Carrierwave to crop and upload the image directly to Amazon S3, the right way to do this for me is:

image_uploader.rb

 url=model.remote_image_url crop_params="#{w}x#{h}+#{x}+#{y}" manipulate! do |img| img = MiniMagick::Image.open(url) img.crop(crop_params) img = yield(img) if block_given? img end 

The reason I add img = MiniMagick :: Image.open (url) is because if I don’t specify my own image, it will cause me an error:

 mogrify.im6: geometry does not contain image `/tmp/mini_magick20150811-15523-ac8go1.jpeg' 

I think this is the default temporary path that mini_magick will try to find the image, but since the image is stored remotely in S3, it cannot find it.

+1
source share

All Articles