Skip to content

Instantly share code, notes, and snippets.

@closer
Created January 20, 2010 05:56
Show Gist options
  • Select an option

  • Save closer/281646 to your computer and use it in GitHub Desktop.

Select an option

Save closer/281646 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
$KCODE = "u"
require "cgi"
require "kconv"
require "rubygems"
require "rmagick"
include Magick
cgi = CGI.new
w = cgi.params["w"].to_s.toutf8
word = "img.omochi.info"
word = w unless w == ""
WIDTH = 600
HEIGHT = 80
img = ImageList.new
top_grad = GradientFill.new(0, 0, WIDTH, 0, "#dddddd", "#888888")
img << Image.new(WIDTH, HEIGHT, top_grad){
self.format = 'JPG'
}
bottom_grad = GradientFill.new(0, 0, WIDTH, 0, "#757575", "#555555")
img << Image.new(WIDTH, HEIGHT, bottom_grad){
self.format = 'JPG'
}
combined_grad = img.append(true)
color = Image.new(combined_grad.columns, combined_grad.rows) {|f|
f.background_color = "#87a5ff"
}
background = combined_grad.composite(color, CenterGravity, ColorizeCompositeOp)
text = Draw.new
text.font = "/System/Library/Fonts/ヒラギノ角ゴ ProN W3.otf"
text.fill = "#FFFFFF"
text.pointsize = 40
text.annotate(background, 0, 0, 70, HEIGHT, word)
reflection = img[1].flip
reflection.composite!(color, CenterGravity, ColorizeCompositeOp)
text.annotate(reflection, 0, 0, 70, HEIGHT, word)
grad = GradientFill.new(0, 0, WIDTH, 0, "black", "gray35")
opacity_mask = Image.new(WIDTH, HEIGHT, grad)
reflection.matte = true
opacity_mask.matte = false
reflection.composite!(opacity_mask, CenterGravity, CopyOpacityCompositeOp)
reflection.flip!
background.composite!(reflection, SouthWestGravity, OverCompositeOp)
shadow = Image.new(background.columns+10, background.rows+10) {
self.format = "JPG"
}
g = Draw.new
g.fill("gray30")
g.rectangle(5, 5, background.columns+5, background.rows+5)
g.draw(shadow)
shadow = shadow.blur_image(0, 2)
shadowed_background = shadow.composite(background, CenterGravity, OverCompositeOp)
print "Content-Type: image/jpeg\n\n"
print shadowed_background.to_blob
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment