我用的是dragonfly ~> 0.9.15
给定一个图像,我很困惑如何在蜻蜓中使用转换方法从透明背景的图像中裁剪一个圆形部分。
我可以使用一个直接的映像magick命令从命令行运行它,但是我找到的示例命令使用的是实际文件,而且我不知道如何在蜻蜓动态处理文件时获取该文件。
下面是使用imagemagick从堆栈溢出问题中获得的实际命令。
https://stackoverflow.com/a/999563/1664852
convert -size 200x200 xc:none -fill walter.jpg -draw "circle 100,100 100,1" circle_thumb.png当我试图用蜻蜓实现同样的目标时,这就是配置:
require 'dragonfly/rails/images'
Dragonfly[:images].configure do |c|
c.job :crop_circle do
process :resize, "320x440"
encode :png
process :convert, '-virtual-pixel HorizontalTile -background transparent -draw "circle 400,400 400,1" -compose Copy_Opacity -composite'
end
end当它在服务器日志中运行时,我会得到错误no such image。
如何使用imagemagick命令为此配置convert函数?
发布于 2014-09-09 17:39:24
也许我的解决方案可以帮助那些正在寻找用蜻蜓宝石生成圆形图像的人。
我无法找到一个现成的解决方案,但我设法把一些东西拼凑在一起,在这里和那里一点点。
事实证明,使用ImageMagick (6.89-1)制作圆角图像的方法非常简单,使用的是在此解释选项。
下面的命令行将生成一个背景透明且图像四舍五入的图像:
convert profile.png -alpha set -background none -thumbnail 50x50^ -vignette 0x0 rounded_profile.png现在,我们可以通过在dragonfly.rb初始化器中添加一个:圆形处理器来获得概要文件图片的圆角图像,如下所示:
require 'dragonfly'
# Configure
Dragonfly.app.configure do
plugin :imagemagick
# Fictive secret no worries
secret "64d123456dafb767892c1d28ca6d123456ea4cc373dac117d6d1123456a29d6e"
url_format "/media/:job/:name"
datastore :file,
root_path: Rails.root.join('public/system/dragonfly', Rails.env),
server_root: Rails.root.join('public')
processor :rounded do |content, size|
content.shell_update ext: 'png' do |old_path, new_path|
"/usr/local/bin/convert #{old_path} -alpha set -background none -thumbnail #{size}^ -vignette 0x0 #{new_path}"
end
end
end请注意,您可能必须根据您正在运行的平台、我在Mac上和ImageMagick是通过Homebrew安装的平台来更改转换命令的路径。
现在,从具有蜻蜓处理的图像的任何模型中,您可以调用:
a_model_instance.an_image.rounded('50x50').url若要返回50 by乘50 by的圆形图像,请执行以下操作。
https://stackoverflow.com/questions/20477809
复制相似问题