Rmagick图形处理(不规则四边)

阅读更多
 

def self.showimg(len,imgname,content)

 cur = 10

 

 canvas = Magick::ImageList.new

 #granite=Magick::ImageList.new.from_blob(imgname)

 #granite=granite.frame(width=20, height=20, x=20, y=20, inner_bevel=3, outer_bevel=1, color='gray75')

 #granite=granite.border(5, 5, 'red')

 

 granitet = Magick::ImageList.new.new_image(500,380)do   

 self.background_color = 'gray'

 end

 

 

granite =Magick::ImageList.new.from_blob(imgname)

img_y=granite.rows

img_x=granite.columns

points=[1,8]

temp=1

while temp<=10

  points<10)

  points<10)+(img_y/10)*(temp-1)

  temp+=1

end

temp=1

while temp<=18

  points<9)+(img_x/18)*temp

  points<62+rand(8)

  temp+=1

end

temp=1

while temp<=10

  points<46+rand(15)

  points<10)+(img_y/10)*(10-temp)

  temp+=1

end

temp=1

while temp<=18

  points<10)+(granite.rows/18)*(18-temp)

   points<11)

  temp+=1

end

pr = Magick::Draw.new

pr.define_clip_path('example') {

    pr.polygon(*points)

    }

pr.clip_path('example')

tf=Magick::ImageList.new("public/images/model1/jitian.gif")

granite = granite.composite(tf,rand(200),rand(200), Magick::OverCompositeOp)

cols = rows = nil

granite.change_geometry("350") do |c,r|

    pr.composite(0,0, c, r, granite)

    cols = c

    rows = r

end

 text = Magick::Draw.new

 canvas.new_image(800,680)  do   

 self.background_color = 'gray'

 end

  pr.draw(granitet)

  canvas = canvas.composite(granitet,220,220, Magick::InCompositeOp)

 

   #canvas=canvas.border(5, 5, 'red')

   #text=text.stroke_opacity(0.1)

   #text=text.opacity(0.1)

   #text=text.fill_opacity(0.1)

   #tft=Magick::ImageList.new

 

  text.annotate(canvas,0,0,10,10,CGI.unescape(content)) do 

      self.rotation=0

      #self.encoding='gbk'

      self.pointsize = 20

      self.font_weight = Magick::BoldWeight

      self.fill = 'white'

      self.gravity = Magick::SouthEastGravity

  end

 

  @myimage = canvas.to_blob{self.format="jpg"}

 

end

你可能感兴趣的:(C,C++,C#,CGI)