Skip to content

Instantly share code, notes, and snippets.

@davidjrice
Created September 8, 2008 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidjrice/9351 to your computer and use it in GitHub Desktop.
Save davidjrice/9351 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'RMagick'
size = [85,85]
dst = Magick::Image.read("frame2.svg") {
self.background_color = 'white'
}.first
src = Magick::Image.read('lime.jpg').first
dst = dst.transparent('white', Magick::TransparentOpacity)
[src,dst].each do |src|
if src.columns > src.rows
width = size.first
height = size.last
# Wider than tall...use height
src = src.change_geometry("x#{height}") { |cols, rows, image|
image.resize!(cols, rows)
image.crop! Magick::CenterGravity, 0, 0, width, height
}
elsif src.columns < src.rows
width = size.last
height = size.first
#Taller than wide... use width
src = src.change_geometry("#{width}") { |cols, rows, image|
image.resize!(cols, rows)
image.crop! Magick::CenterGravity, 0, 0, width, height
}
elsif src.columns == src.rows
width = size.first
height = size.last
src.resize!(width,height)
src.crop! Magick::CenterGravity, 0, 0, width, height
end
end
result = src.composite(dst, Magick::CenterGravity, Magick::OverCompositeOp)
result.write('framed.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment