Module: ChunkyPNG::RMagick

### Home Classes Methods

### In Files

- lib/chunky_png/rmagick.rb

### Methods

- #export
- #import

### Files

- BENCHMARKING.rdoc
- CHANGELOG.rdoc
- CONTRIBUTING.rdoc
- README.rdoc

### Class/Module Index

Quicksearch

- ChunkyPNG
- ChunkyPNG::CRCMismatch
- ChunkyPNG::Canvas
- ChunkyPNG::Canvas::Adam7Interlacing
- ChunkyPNG::Canvas::DataUrlExporting
- ChunkyPNG::Canvas::DataUrlImporting
- ChunkyPNG::Canvas::Drawing
- ChunkyPNG::Canvas::Masking
- ChunkyPNG::Canvas::Operations
- ChunkyPNG::Canvas::PNGDecoding
- ChunkyPNG::Canvas::PNGEncoding
- ChunkyPNG::Canvas::Resampling
- ChunkyPNG::Canvas::StreamExporting
- ChunkyPNG::Canvas::StreamImporting
- ChunkyPNG::Chunk
- ChunkyPNG::Chunk::Base
- ChunkyPNG::Chunk::CompressedText
- ChunkyPNG::Chunk::End
- ChunkyPNG::Chunk::Generic
- ChunkyPNG::Chunk::Header
- ChunkyPNG::Chunk::ImageData
- ChunkyPNG::Chunk::InternationalText
- ChunkyPNG::Chunk::Palette
- ChunkyPNG::Chunk::Text
- ChunkyPNG::Chunk::Transparency
- ChunkyPNG::Color
- ChunkyPNG::Datastream
- ChunkyPNG::Dimension
- ChunkyPNG::Exception
- ChunkyPNG::ExpectationFailed
- ChunkyPNG::Image
- ChunkyPNG::NotSupported
- ChunkyPNG::OutOfBounds
- ChunkyPNG::Palette
- ChunkyPNG::Point
- ChunkyPNG::RMagick
- ChunkyPNG::SignatureMismatch
- ChunkyPNG::Vector
- Enumerable
- String

No matching classes.

# ChunkyPNG::RMagick

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.

@example

    require 'rmagick'
    require 'chunky_png/rmagick'

    canvas = ChunkyPNG::Canvas.from_file('filename.png')
    image = ChunkyPNG::RMagick.export(canvas)

    # do something with the image using RMagick

    updated_canvas = ChunkyPNG::RMagick.import(image)

### Public Instance Methods

export(canvas) click to toggle source

Exports a Canvas as RMagick image instance. @param [ChunkyPNG::Canvas] canvas The canvas to export. @return [Magick::Image] The RMagick image constructed from the Canvas instance.

    # 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) click to toggle source

Imports an RMagick image as Canvas object. @param [Magick::Image] image The image to import @return [ChunkyPNG::Canvas] The canvas, constructed from the RMagick image.

    # 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.