Class: ActFunc::Ttmagick
- Inherits:
-
Object
- Object
- ActFunc::Ttmagick
- Defined in:
- lib/act_func/tmagick.rb
Instance Method Summary collapse
-
#images(images) ⇒ Object
图片叠加和水印 images->多图片叠加,数组,在一个图片上画多个图片; image=>“1.jpg”, x: 0, y: 0,img要画的图片地址,xy画的左顶点位置 return->成功返回当前对象,失败返回nil.
-
#initialize(img, newimg = nil) ⇒ Ttmagick
constructor
画图类 img->底图 “#Rails.root/public/images/1.jpg” newimg->处理完保存的地址 save img handle path example->“#Rails.root/public/images/new.jpg” example-> Tmagick.new(“1.jpg”,“public/n.jpg”).images(images),texts(texts).images(imgs).write.
-
#resize(new_width, new_height) ⇒ Object
重定义图片大小.
-
#texts(texts) ⇒ Object
图片上写字 fontobjs 文字数组; fontobj=>“aaaaaaaaa”,color: “#000000”,font: “simsun.ttc’”,size: 20,weight: 100, x: 0, y: 0 text文字内容,color颜色,font字体,size大小,weight粗细,xy画的左顶点位置 return-》成功返回当前对象,失败返回nil.
-
#write ⇒ Object
写出操作.
Constructor Details
#initialize(img, newimg = nil) ⇒ Ttmagick
画图类img->底图 “#Rails.root/public/images/1.jpg” newimg->处理完保存的地址 save img handle path example->“#Rails.root/public/images/new.jpg” example-> Tmagick.new(“1.jpg”,“public/n.jpg”).images(images),texts(texts).images(imgs).write
7 8 9 10 |
# File 'lib/act_func/tmagick.rb', line 7 def initialize(img, newimg=nil) @pushimg = Magick::Image.read(img).first @poppath = newimg.blank? ? img : newimg end |
Instance Method Details
#images(images) ⇒ Object
图片叠加和水印images->多图片叠加,数组,在一个图片上画多个图片; image=>“1.jpg”, x: 0, y: 0,img要画的图片地址,xy画的左顶点位置return->成功返回当前对象,失败返回nil
15 16 17 18 19 20 21 22 |
# File 'lib/act_func/tmagick.rb', line 15 def images(images) return nil if images.blank? images.each do |img| image = Magick::Image.read(img[:img]).first.resize_to_fit(img[:w], img[:h]) @pushimg.composite!(image, img[:x], img[:y], Magick::OverCompositeOp) end return self end |
#resize(new_width, new_height) ⇒ Object
重定义图片大小
42 43 44 45 |
# File 'lib/act_func/tmagick.rb', line 42 def resize(new_width, new_height) @pushimg = Magick::Image.read(@pushimg).first.resize_to_fit(new_width, new_height) @pushimg.blank? ? nil : self end |
#texts(texts) ⇒ Object
图片上写字fontobjs 文字数组; fontobj=>“aaaaaaaaa”,color: “#000000”,font: “simsun.ttc’”,size: 20,weight: 100, x: 0, y: 0
text
return-》成功返回当前对象,失败返回nil
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/act_func/tmagick.rb', line 28 def texts(texts) return nil if texts.blank? texts.each do |text| copyright = Magick::Draw.new copyright.font = text[:font] copyright.pointsize = text[:size] copyright.font_weight = text[:weight] copyright.fill = text[:color] copyright.annotate(@pushimg, 0, 0, text[:x], text[:y]+12, text[:text]) end return self end |
#write ⇒ Object
写出操作
48 49 50 |
# File 'lib/act_func/tmagick.rb', line 48 def write @pushimg.write(@poppath) end |