Skip to content

Instantly share code, notes, and snippets.

@dethe
Created August 13, 2010 04:51
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 dethe/522311 to your computer and use it in GitHub Desktop.
Save dethe/522311 to your computer and use it in GitHub Desktop.
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