gpt4 book ai didi

ruby-on-rails - Rails 4 Carrierwave + Minimagick : Failed to manipulate with MiniMagick, 也许它不是图像?原始错误:`mogrify -crop

转载 作者:行者123 更新时间:2023-12-01 03:36:08 25 4
gpt4 key购买 nike

一直在研究但未能查明问题:我正在关注 Railscasts PRO #182 使用 JCrop、Carrierwave 和 Minimagick 裁剪图像。当我开始重新创建图像版本时,提示错误:

CarrierWave::ProcessingError (Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: mogrify -crop! 250x250+531+32 /tmp/mini_magick20160108-6544-1ec50pf.png failed with error: mogrify: unrecognized option -crop!' @ error/mogrify.c/MogrifyImageCommand/4197.
):
app/uploaders/image_uploader.rb:48:in
crop' app/models/course.rb:15:in crop_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

Controller
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

图片上传器
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

最佳答案

原来是选项 -crop!命令 mogrify 中不存在。分辨率只是改变 .crop!裁剪

即在 ImageUploader 中:
img.crop!("#{w}x#{h}+#{x}+#{y}") --> img.crop("#{w}x#{h}+#{x}+#{y}")

关于ruby-on-rails - Rails 4 Carrierwave + Minimagick : Failed to manipulate with MiniMagick, 也许它不是图像?原始错误:`mogrify -crop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34669235/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com