Skip to content

Instantly share code, notes, and snippets.

@xNekOIx
Last active August 30, 2015 11:32
Show Gist options
  • Save xNekOIx/5279ac54c76bbc72cd8b to your computer and use it in GitHub Desktop.
Save xNekOIx/5279ac54c76bbc72cd8b to your computer and use it in GitHub Desktop.
Button image via ImageMagick
#!/usr/bin/env ruby
image_name = "action-background"
width = 29
height = 28
color = '#EF3F39'
stroke_width = 1
stroke = '#EF3F39'
corner_radius = 14
# shadow?
for i in 1..3
make_image_cmd = "convert -size #{width*i}x#{height*i} xc:none -fill '#{color}' "
stroke_defined = (defined? stroke and !stroke.nil?) and \
(defined? stroke_width and !stroke_width.nil? and stroke_width > 0)
if stroke_defined
make_image_cmd += "-stroke '#{stroke}' -strokewidth #{stroke_width*i} "
end
corner_radius_defined = defined? corner_radius and !corner_radius.nil? and corner_radius > 0
if corner_radius_defined
corner_radius_offset = (i*stroke_width/2).ceil
rect = "#{corner_radius_offset},#{corner_radius_offset} #{width*i-corner_radius_offset-1},#{height*i-corner_radius_offset-1} "
make_image_cmd += "-draw 'roundrectangle #{rect} #{corner_radius*i},#{corner_radius*i}' "
else
rect = "0,0 #{width*i-1},#{height*i-1} "
make_image_cmd += "-draw 'rectangle #{rect}' "
end
if i == 1
make_image_cmd += "#{image_name}.png"
else
make_image_cmd += "#{image_name}@#{i}x.png"
end
`#{make_image_cmd}`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment