Created
August 13, 2010 04:51
-
-
Save dethe/522311 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 'cairo' | |
require 'rmagick' | |
img = Magick::Image::read('test.jpg').first | |
puts 'Getting bounding box' | |
width = img.columns | |
height = img.rows | |
puts 'Finding stride for width ' + width.to_s | |
stride = Cairo::Format::stride_for_width(:argb32, width) | |
puts 'Getting data from image, stride = ' + stride.to_s | |
data = img.export_pixels_to_str(0,0,width,height,'PRGB', Magick::CharPixel) | |
puts 'Creating new cairo surface with image data' | |
Cairo::ImageSurface.new(data, :argb32, width, height, stride) do |surface| | |
puts 'Writing new surface to file' | |
surface.write_to_png('test-from-jpg.png') | |
end | |
puts 'All done, exiting' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment