未定义的方法!在导轨3.1.3上使用带MiniMagick的载波 [英] Undefined Method crop! Using Carrierwave with MiniMagick on rails 3.1.3

查看:53
本文介绍了未定义的方法!在导轨3.1.3上使用带MiniMagick的载波的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了一点时间来使它工作,现在仍然如此。我会尽全力。我正在关注Ryan Bates教程,以使用Jcrop和Carrierwave进行裁剪。我之所以选择使用MiniMagick,是因为即使在我的计算机上重新安装了ImageMagick和RMagick之后,我仍然遇到一个错误,该错误会杀死本地计算机上的rails服务器。无论如何,切换到MiniMagick对我来说就是固定的。
因此,到目前为止一切都还不错。我制作的图像大小不同,并且已成功上传。
但是一旦我尝试裁剪,就会出现此错误:

I was having a heck of a time getting this to work, and still am. I'll get to the heart of it. I'm following Ryan Bates tutorial to make cropping work using Jcrop and Carrierwave. I've opted to use MiniMagick because even after reinstalling ImageMagick and RMagick on my machine I get an error that kills the rails server on my local machine. Anyway switching to MiniMagick fixed that for me. So everything is really nice up until this point. I have different sized images being produced, and they're being uploaded successfully. But once I try to crop I get this error:

undefined method `crop!' for #<MiniMagick::CommandBuilder:0x000001052e4608>

这让我很困惑,因为我使用的代码与Bates完全相同:

This is confusing the heck out of me because I'm using pretty much the exact same code as Bates:

def crop
if model.crop_x.present?
  resize_to_limit(700, 700)
  manipulate! do |img|
    x = model.crop_x.to_i
    y = model.crop_y.to_i
    w = model.crop_w.to_i
    h = model.crop_h.to_i
    img.crop!(x, y, w, h)
  end
 end
end

无论如何,就是那种裁剪方法失败了。所以我对自己想,那是一个ImageMagick命令...所以我看了看ImageMagick doco,但找不到带有爆炸声的裁剪方法,所以我尝试了一下,但错误变成了这样:

Anyway, it's that crop method that's failing. So I thought to myself, that's an ImageMagick command... So I looked at the ImageMagick doco, and I couldn't find the crop method with the bang, so I tried it without, and then the error turns to this:

No such file or directory - /var/folders/dF/dFNM2+Y7FVScn4+OxVHKOU+++TI/-Tmp-/mini_magick20111207-34409-1tnaa07.jpg

无论如何,任何事情对我来说都意义不大帮助将不胜感激!
感谢您的阅读!

Anyway, something isn't making a ton of sense to me, any help would be appreciated! Thanks for reading!

推荐答案

遇到同样的问题,我的解决方法是这种方法

Had the same problems, my solution was this method

def cropped_image(params)
    image = MiniMagick::Image.open(self.image.path)
    crop_params = "#{params[:w]}x#{params[:h]}+#{params[:x]}+#{params[:y]}"
    image.crop(crop_params)

    image
end

只需为您的案例修改我的方法。

关键是采用哪种格式将变量传递给裁剪方法,希望这对您有所帮助。

Just modify my method for your case.
The key is in which format pass variables to crop method, hope this helps you.

这篇关于未定义的方法!在导轨3.1.3上使用带MiniMagick的载波的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆