use*_*086 3 watermark ruby-on-rails rmagick ruby-on-rails-4
我想用RMagick在我的图像上添加文字.这是我的代码:
version :thumb do
process :resize_to_limit => [400, 300]
process :addt
end
def addt
manipulate! do |img|
title = Magick::Draw.new
img = title.annotate(img, 0,0,0,40, 'test') {
self.font_family = 'Helvetica'
self.fill = 'white'
self.stroke = 'transparent'
self.pointsize = 32
self.font_weight = Magick::BoldWeight
self.gravity = Magick::CenterGravity
}
end
end
Run Code Online (Sandbox Code Playgroud)
这段代码的问题在于它完全阻止了我的应用程序.我无法打开我的网站的任何其他部分,无法关闭我的服务器进程.我需要完全杀死服务器进程才能再次启动应用程序.
可能有什么问题?
小智 7
试试这个,我无法解决你的代码.但希望这个可以帮助你.
第一次安装这个宝石 来源: https ://github.com/rmagick/rmagick
下一步要开始玩RMagick,你可以将它放在你的一个控制器中:
require ‘RMagick’
include Magick
def addt
img = ImageList.new(‘Your image path eg.public/computer-cat.jpg’)
txt = Draw.new
img.annotate(txt, 0,0,0,0, “The text you want to add in the image”){
txt.gravity = Magick::SouthGravity
txt.pointsize = 25
txt.stroke = ‘#000000?
txt.fill = ‘#ffffff’
txt.font_weight = Magick::BoldWeight
}
img.format = ‘jpeg’
send_data img.to_blob, :stream => ‘false’, :filename => ‘test.jpg’, :type => ‘image/jpeg’, :disposition => ‘inline’
end
Run Code Online (Sandbox Code Playgroud)
希望这一个帮助你..
如果你不明白..点击这里http://mikewilliamson.wordpress.com/2010/04/29/adding-text-to-pictures-with-rmagick-and-rails/
| 归档时间: |
|
| 查看次数: |
3282 次 |
| 最近记录: |