Module: ChunkyPNG::RMagick
Overview
Methods for importing and exporting RMagick image objects.
By default, this module is disabled because of the dependency on RMagick. You need to include this module yourself if you want to use it.
Instance Method Summary collapse
-
#export(canvas) ⇒ Magick::Image
Exports a Canvas as RMagick image instance.
-
#import(image) ⇒ ChunkyPNG::Canvas
Imports an RMagick image as Canvas object.
Instance Method Details
#export(canvas) ⇒ Magick::Image
Exports a Canvas as RMagick image instance.
37 38 39 40 41 |
# File 'lib/chunky_png/rmagick.rb', line 37 def export(canvas) image = Magick::Image.new(canvas.width, canvas.height) image.import_pixels(0, 0, canvas.width, canvas.height, "RGBA", canvas.pixels.pack("N*")) image end |
#import(image) ⇒ ChunkyPNG::Canvas
Imports an RMagick image as Canvas object.
29 30 31 32 |
# File 'lib/chunky_png/rmagick.rb', line 29 def import(image) pixels = image.export_pixels_to_str(0, 0, image.columns, image.rows, "RGBA") ChunkyPNG::Canvas.from_rgba_stream(image.columns, image.rows, pixels) end |