I would like to alter the processing of thumbnails in paperclip by having imagemagick apply a drop shadow to all the thumbnails. What I'm stuck on is the actual imagemagick command that would pull this little miracle off. Everything I've tried returns an incorrectly scaled drop shadow without the original image.
我想通过使用imagemagick对所有缩略图应用投影来改变回形针中缩略图的处理。我坚持的是实际的imagemagick命令,它将把这个小奇迹拉下来。我尝试过的所有内容都会返回不正确缩放的投影,而不会显示原始图像。
def transformation_command
scale, crop = @current_geometry.transformation_to(@target_geometry, crop?)
trans = ""
trans << " -resize \"#{scale}\""
trans << " -crop \"#{crop}\" +repage" if crop
# Apply Drop Shadow
trans << " #{convert_options}" if convert_options?
trans
end
One I've tried...
一个我试过......
def transformation_command
scale, crop = @current_geometry.transformation_to(@target_geometry, crop?)
trans = ""
trans << " -resize \"#{scale}\""
trans << " -crop \"#{crop}\" +repage" if crop
trans << " \( +clone -background black -shadow 60x5+10+10 \) +swap -background none -layers merge +repage"
trans << " #{convert_options}" if convert_options?
trans
end
I'm completely new to imagemagick, any help would be greatly appreciated.
我对imagemagick完全陌生,任何帮助都会非常感激。
2 个解决方案
#1
After some trial and error and burying my head in the docs, I finally figured it out.
经过一些试验和错误并将我的头埋在文档中后,我终于明白了。
has_attached_file :image,
:styles => { :thumb => ["100x100#", :png] },
:convert_options => { :thumb => '\( +clone -background black -shadow 70x4+0+0 \) +swap -background none -layers merge +repage' }
- Make sure you have the latest version of ImageMagick installed.
- ["100x100#", :png] will convert the image to png so the drop shadow is transparent.
- Under convert options, :thumb will only apply the conversion to the :thumb style, use :all to apply the conversion to all your styles.
- Tweak "70x4+0+0" to get the shadow you want.
确保安装了最新版本的ImageMagick。
[“100x100#”,:png]会将图像转换为png,因此投影是透明的。
在转换选项下,:thumb仅将转换应用于:thumb样式,使用:all将转换应用于所有样式。
调整“70x4 + 0 + 0”以获得您想要的阴影。
#2
I find it a lot easier to just use the rmagick interface rather then sending command line options to imagemagick itself.
我发现使用rmagick接口而不是将命令行选项发送到imagemagick本身要容易得多。
If you use rmagick you can use the shadow method.
如果使用rmagick,则可以使用shadow方法。
img = Image.read('slide.png').first
shadow = img.shadow(0, 0, 0.0, '20%')
and then composite the image over the shadow.
然后将图像合成阴影。
I wrote an article on using rmagick: http://schf.uc.org/articles/2006/10/18/render-greatlooking-collages-with-ruby-and-rmagick
我写了一篇关于使用rmagick的文章:http://schf.uc.org/articles/2006/10/18/render-greatlooking-collages-with-ruby-and-rmagick
Try reading it over it might give you a better understanding.
尝试阅读它可能会让你更好地理解。
I also wrote an abstraction lib to rmagick which attempts to make it even easier to use. I called it RubyShop because it tried to mimic photoshop layer based compositing.. (I really hate the name and will probably change it if I ever resurrect the project)
我还为rmagick编写了一个抽象库,试图让它更容易使用。我称它为RubyShop,因为它试图模仿基于photoshop层的合成..(我真的很讨厌这个名字,如果我复活这个项目,它可能会改变它)
#1
After some trial and error and burying my head in the docs, I finally figured it out.
经过一些试验和错误并将我的头埋在文档中后,我终于明白了。
has_attached_file :image,
:styles => { :thumb => ["100x100#", :png] },
:convert_options => { :thumb => '\( +clone -background black -shadow 70x4+0+0 \) +swap -background none -layers merge +repage' }
- Make sure you have the latest version of ImageMagick installed.
- ["100x100#", :png] will convert the image to png so the drop shadow is transparent.
- Under convert options, :thumb will only apply the conversion to the :thumb style, use :all to apply the conversion to all your styles.
- Tweak "70x4+0+0" to get the shadow you want.
确保安装了最新版本的ImageMagick。
[“100x100#”,:png]会将图像转换为png,因此投影是透明的。
在转换选项下,:thumb仅将转换应用于:thumb样式,使用:all将转换应用于所有样式。
调整“70x4 + 0 + 0”以获得您想要的阴影。
#2
I find it a lot easier to just use the rmagick interface rather then sending command line options to imagemagick itself.
我发现使用rmagick接口而不是将命令行选项发送到imagemagick本身要容易得多。
If you use rmagick you can use the shadow method.
如果使用rmagick,则可以使用shadow方法。
img = Image.read('slide.png').first
shadow = img.shadow(0, 0, 0.0, '20%')
and then composite the image over the shadow.
然后将图像合成阴影。
I wrote an article on using rmagick: http://schf.uc.org/articles/2006/10/18/render-greatlooking-collages-with-ruby-and-rmagick
我写了一篇关于使用rmagick的文章:http://schf.uc.org/articles/2006/10/18/render-greatlooking-collages-with-ruby-and-rmagick
Try reading it over it might give you a better understanding.
尝试阅读它可能会让你更好地理解。
I also wrote an abstraction lib to rmagick which attempts to make it even easier to use. I called it RubyShop because it tried to mimic photoshop layer based compositing.. (I really hate the name and will probably change it if I ever resurrect the project)
我还为rmagick编写了一个抽象库,试图让它更容易使用。我称它为RubyShop,因为它试图模仿基于photoshop层的合成..(我真的很讨厌这个名字,如果我复活这个项目,它可能会改变它)