一直在研究但未能确定问题:我正在使用JCrop,Carrierwave和Minimagick关注裁剪图像的Railscasts PRO#182。当我重新创建图像版本时,我被提示错误:
CarrierWave :: ProcessingError(无法使用MiniMagick进行操作,也许它不是图像?原始错误:
mogrify -crop! 250x250+531+32 /tmp/mini_magick20160108-6544-1ec50pf.png
失败并显示错误: mogrify:无法识别的选项-crop!' @ error/mogrify.c/MogrifyImageCommand/4197. ): app/uploaders/image_uploader.rb:48:in
crop' app / models / course.rb:15:incrop_image' app/controllers/courses_controller.rb:12:in
update'
有人可以帮我理解这个错误的含义吗?
模型
class Course < ActiveRecord::Base
attr_accessor :crop_x, :crop_y, :crop_w, :crop_h
after_update :crop_image
mount_uploader :image, ImageUploader
def crop_image
image.recreate_versions! if crop_x.present?
end
end
控制器
class CoursesController < ApplicationController
def update
@course = Course.find(params[:id])
if @course.update_attributes(course_params)
if course_params[:image].present?
render :crop
else
redirect_to @course, notice: 'Successfully updated'
end
end
end
def course_params
params.require(:course).permit(:title, :image, :crop_x, :crop_y, :crop_w, :crop_h)
end
end
ImageUploader
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :thumb do
process :crop
process :resize_to_fit => [250, 250]
end
def crop
if model.crop_x.present?
resize_to_fit(800, 350)
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!("#{w}x#{h}+#{x}+#{y}")
end
end
end
end
答案 0 :(得分:2)
原来选项-crop!命令mogrify中不存在。决议只是改变.crop!到.crop
即。在ImageUploader中:
img.crop!("#{w}x#{h}+#{x}+#{y}")
- &gt; img.crop("#{w}x#{h}+#{x}+#{y}")
答案 1 :(得分:0)
strip
遇到相同的问题。仅在图像较大时发生。
此问题的第一期是2012年,没有一个很好的解决方案就关闭了。