Created
September 8, 2008 01:12
-
-
Save davidjrice/9351 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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