用minmagick 在图片写字(包含中文,英文标点)(感觉比较麻烦,但是可行)

require 'rubygems'
require 'mini_magick'
include MiniMagick
image = MiniMagick::Image.from_file("1.jpg")
str = str.gsub("\"","\\\"") if str.include?("\"") #如果包含",则在ImageMagick层次转义
str = str.gsub("'","\\\\'") if str.include?("'") ##如果包含',则在ImageMagick层次转义
image.run_command("mogrify","-font /usr/share/fonts/truetype/arphic/uming.ttc","-weight Bolder","-pointsize 17","-draw","fill red text 66,88 '#{str}'",image.tempfile.path)
image.write("2.jpg")

你可能感兴趣的:(rubygems)