Unable to crop image using mini_magick

不羁的心 提交于 2019-12-08 16:56:54

问题


I am using mini_magick as the interface of utilizing ImageMagick to manipulate some image. The resize works fine. But when I want to crop some image:

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

It constantly prompts No such file

No such file or directory - /var/folders/c4/mqlwdx_d3kj6hqcnvbjr9mn80000gn/T/mini_magick20120504-11111-16kayc1.png

回答1:


Ah, I was searching with wrong key phrase I guess. The right answer come to me when I search minimagick instead of mini_magick. Undefined Method crop! Using Carrierwave with MiniMagick on rails 3.1.3 especially this answer https://stackoverflow.com/a/9961434/179691

I did know the stuff about mini_magick is just a wrapping of mogrify and so. The cause of my problem is that -crop accepts full formatted geometry only. so I changed the expression to:

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

and that works.




回答2:


Just in case if anyone is using Carrierwave to crop and upload image directly to Amazon S3, the correct way to do for me is the following:

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'm adding img = MiniMagick::Image.open(url) is because if I don't specify my own image, it would throw me the following error:

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

I think it's some default temporary path that mini_magick would try to find the image, but since the image is held remotely in S3, it couldn't find it.



来源:https://stackoverflow.com/questions/10448032/unable-to-crop-image-using-mini-magick

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!