我正在使用回形针来存储我的图像,我想创建一个裁剪/旋转的图像作为缩略图。这里是回形针应该运行的正常命令:停止回形针剪裁和其他参数之前调整大小
convert [file].jpg -gravity center -distort SRT -30 -quality 100 -antialias -flatten -background white -unsharp 0.3x0.3+5+0 -crop 433x433+69+88 +repage -resize "300x300>" [file].jpg
这产生了我想要的结果。我已经在安装了imagemagick的电脑上直接测试了它。然而,在我的服务器上查看日志,这些参数的顺序是不同的。回形针希望a)把-resize "300x300>"
命令首先,然后放-crop 433x433+69+88
第二,然后再把其余的论点。这改变了最终图像的外观!不是我想要的。下面是它在日志输出:
convert [file].jpg -auto-orient -resize "300x300>" -crop 433x433+69+88 +repage -gravity center -distort SRT -30 -quality 100 -antialias -flatten -background white -unsharp 0.3x0.3+5+0 [file].jpg
...这是我在我的模型配置:
Wine.rb
has_attached_file :photo, :styles => {
:thumb => {
:geometry => "300x300>",
:format => :jpg,
:processors => [:cropper, :recursive_thumbnail],
:thumbnail => :croppable
},
:general => ["150x375", :jpg],
:show => ["x425", :jpg],
:croppable => ["1200x1200>", :jpg]
},
:url => "/assets/wines/:style/:wine_name",
:path => ":rails_root/public:url",
:default_url => ":wine_default",
:default_path => ":rails_root/public:wine_default",
:default_style => :show,
:convert_options => {
:thumb => '-gravity center -distort SRT -30',
:croppable => '-gravity center -extent 1200x1200',
:general => '-gravity center -extent 150x375 -quality 95',
:all => '-quality 100 -antialias -flatten -background white -unsharp 0.3x0.3+5+0'
},
:processors => [:thumbnail, :compression]
基本上它在这个运行CONVERT.EXE命令:[:geometry] [:transformations] [:convert_options]。
我如何按照我想要的顺序获取东西?
recursive_thumbnail.rb - 用于运行:拇指缩略图生成断:croppable而不是原来的文件(因为水平填充问题裁剪时)
module Paperclip
class RecursiveThumbnail < Thumbnail
def initialize file, options = {}, attachment = nil
super Paperclip.io_adapters.for(attachment.styles[options[:thumbnail] || :original]), options, attachment
end
end
end
cropper.rb
module Paperclip
class Cropper < Thumbnail
def transformation_command
if crop_command
super.join(' ').sub(/ -crop \S+/, '').split(' ') + crop_command
else
super
end
end
def crop_command
target = @attachment.instance
if target.cropping?
["+repage", "-crop", "#{target.crop_w}x#{target.crop_h}+#{target.crop_x}+#{target.crop_y}", "+repage"]
end
end
end
end
希望我能帮忙,但我只能推荐使用标准回形针功能来处理这种事情:)如果你想让我给你一些想法,我可以做一个答案? –
当然,无论帮助,帮助。我甚至可以做一个自定义滚动的处理器,它将覆盖Paperclip用于生成缩略图的默认过程,但我不知道从哪里开始。 – JakeTheSnake