Class: Magick::Image

### Home Classes Methods

### In Files

- lib/RMagick.rb
- ext/RMagick/rmmain.c

### Parent

Object

### Namespace

- CLASS Magick::Image::DrawOptions
- CLASS Magick::Image::Info
- CLASS Magick::Image::PolaroidOptions
- CLASS Magick::Image::View

### Methods

- #annotate
- #color_fill_to_border
- #color_floodfill
- #color_point
- #color_reset!
- #crop_resized
- #crop_resized!
- #cur_image
- #each_iptc_dataset
- #each_pixel
- #get_exif_by_entry
- #get_exif_by_number
- #get_iptc_dataset
- #level
- #matte_fill_to_border
- #matte_floodfill
- #matte_point
- #matte_replace
- #matte_reset!
- #resample
- #resize_to_fill
- #resize_to_fill!
- #resize_to_fit
- #resize_to_fit!
- #texture_fill_to_border
- #texture_floodfill
- #view

### Included Modules

- Comparable

### Files

- MANIFEST
- Makefile

### Class/Module Index

Quicksearch

- Magick
- Magick::DestroyedImageError
- Magick::Draw
- Magick::Enum
- Magick::FatalImageMagickError
- Magick::Geometry
- Magick::GeometryValue
- Magick::GradientFill
- Magick::HatchFill
- Magick::IPTC
- Magick::IPTC::Application
- Magick::IPTC::Envelope
- Magick::IPTC::ObjectData
- Magick::IPTC::Post_ObjectData_Descriptor
- Magick::IPTC::Pre_ObjectData_Descriptor
- Magick::Image
- Magick::Image::DrawOptions
- Magick::Image::Info
- Magick::Image::PolaroidOptions
- Magick::Image::View
- Magick::Image::View::Pixels
- Magick::Image::View::Rows
- Magick::ImageList
- Magick::ImageList::Montage
- Magick::ImageMagickError
- Magick::OptionalMethodArguments
- Magick::Pixel
- Magick::RVG
- Magick::RVG::Circle
- Magick::RVG::ClipPath
- Magick::RVG::Describable
- Magick::RVG::Duplicatable
- Magick::RVG::Ellipse
- Magick::RVG::Embellishable
- Magick::RVG::Group
- Magick::RVG::Image
- Magick::RVG::ImageConstructors
- Magick::RVG::Line
- Magick::RVG::Path
- Magick::RVG::PathData
- Magick::RVG::Pattern
- Magick::RVG::PolyShape
- Magick::RVG::Polygon
- Magick::RVG::Polyline
- Magick::RVG::PreserveAspectRatio
- Magick::RVG::Rect
- Magick::RVG::ShapeConstructors
- Magick::RVG::Stretchable
- Magick::RVG::StructureConstructors
- Magick::RVG::Stylable
- Magick::RVG::Text
- Magick::RVG::TextBase
- Magick::RVG::TextConstructors
- Magick::RVG::Transformable
- Magick::RVG::Use
- Magick::RVG::UseConstructors
- Magick::RVG::Utility
- Magick::RVG::Utility::DefaultTextStrategy
- Magick::RVG::Utility::GraphicContext
- Magick::RVG::Utility::LRTextStrategy
- Magick::RVG::Utility::RLTextStrategy
- Magick::RVG::Utility::TBTextStrategy
- Magick::RVG::Utility::TextAttributes
- Magick::RVG::Utility::TextStrategy
- Magick::TextureFill
- Object

No matching classes.

# Magick::Image

Ruby-level Magick::Image methods

### Public Instance Methods

annotate(draw, width, height, x, y, text, &block) click to toggle source

Provide an alternate version of Draw#annotate, for folks who want to find it in this class.

    # File lib/RMagick.rb, line 786
    def annotate(draw, width, height, x, y, text, &block)
      check_destroyed
      draw.annotate(self, width, height, x, y, text, &block)
      self
    end

color_fill_to_border(x, y, fill) click to toggle source

Set all pixels that are neighbors of x,y and are not the border color to the fill color

    # File lib/RMagick.rb, line 808
    def color_fill_to_border(x, y, fill)
        color_flood_fill(border_color, fill, x, y, Magick::FillToBorderMethod)
    end

color_floodfill(x, y, fill) click to toggle source

Set all pixels that have the same color as the pixel at x,y and are neighbors to the fill color

    # File lib/RMagick.rb, line 801
    def color_floodfill(x, y, fill)
        target = pixel_color(x, y)
        color_flood_fill(target, fill, x, y, Magick::FloodfillMethod)
    end

color_point(x, y, fill) click to toggle source

Set the color at x,y

    # File lib/RMagick.rb, line 793
    def color_point(x, y, fill)
        f = copy
        f.pixel_color(x, y, fill)
        return f
    end

color_reset!(fill) click to toggle source

Set all pixels to the fill color. Very similar to Image#erase! Accepts either String or Pixel arguments

    # File lib/RMagick.rb, line 814
    def color_reset!(fill)
        save = background_color
        # Change the background color _outside_ the begin block
        # so that if this object is frozen the exeception will be
        # raised before we have to handle it explicitly.
        self.background_color = fill
        begin
            erase!
        ensure
            self.background_color = save
        end
        self
    end

crop_resized(ncols, nrows=nil, gravity=CenterGravity) click to toggle source

Preserve aliases used < RMagick 2.0.1

Alias for: resize_to_fill
crop_resized!(ncols, nrows=nil, gravity=CenterGravity) click to toggle source
Alias for: resize_to_fill!
cur_image() click to toggle source

Used by ImageList methods - see ImageList#cur_image

    # File lib/RMagick.rb, line 829
    def cur_image
        self
    end

each_iptc_dataset() click to toggle source

Iterate over IPTC record number:dataset tags, yield for each non-nil dataset

    # File lib/RMagick.rb, line 891
    def each_iptc_dataset
        Magick::IPTC.constants.each do |record|
            rec = Magick::IPTC.const_get(record)
            rec.constants.each do |dataset|
                data_field = get_iptc_dataset(rec.const_get(dataset))
                yield(dataset, data_field) unless data_field.nil?
            end
        end
        nil
    end

each_pixel() click to toggle source

Thanks to Russell Norris!

    # File lib/RMagick.rb, line 834
    def each_pixel
      get_pixels(0, 0, columns, rows).each_with_index do |p, n|
        yield(p, n%columns, n/columns)
      end
      self
    end

get_exif_by_entry(*entry) click to toggle source

Retrieve EXIF data by entry or all. If one or more entry names specified, return the values associated with the entries. If no entries specified, return all entries and values. The return value is an array of [name,value] arrays.

    # File lib/RMagick.rb, line 845
    def get_exif_by_entry(*entry)
        ary = Array.new
        if entry.length == 0
            exif_data = self['EXIF:*']
            if exif_data
                exif_data.split("\n").each { |exif| ary.push(exif.split('=')) }
            end
        else
            get_exif_by_entry()     # ensure properties is populated with exif data
            entry.each do |name|
                rval = self["EXIF:#{name}"]
                ary.push([name, rval])
            end
        end
        return ary
    end

get_exif_by_number(*tag) click to toggle source

Retrieve EXIF data by tag number or all tag/value pairs. The return value is a hash.

    # File lib/RMagick.rb, line 863
    def get_exif_by_number(*tag)
        hash = Hash.new
        if tag.length == 0
            exif_data = self['EXIF:!']
            if exif_data
                exif_data.split("\n").each do |exif|
                    tag, value = exif.split('=')
                    tag = tag[1,4].hex
                    hash[tag] = value
                end
            end
        else
            get_exif_by_number()    # ensure properties is populated with exif data
            tag.each do |num|
                rval = self['#%04X' % num.to_i]
                hash[num] = rval == 'unknown' ? nil : rval
            end
        end
        return hash
    end

get_iptc_dataset(ds) click to toggle source

Retrieve IPTC information by record number:dataset tag constant defined in Magick::IPTC, above.

    # File lib/RMagick.rb, line 886
    def get_iptc_dataset(ds)
        self['IPTC:'+ds]
    end

level(black_point=0.0, white_point=nil, gamma=nil) click to toggle source

(Thanks to Al Evans for the suggestion.)

    # File lib/RMagick.rb, line 915
    def level(black_point=0.0, white_point=nil, gamma=nil)
        black_point = Float(black_point)

        white_point ||= Magick::QuantumRange - black_point
        white_point = Float(white_point)

        gamma_arg = gamma
        gamma ||= 1.0
        gamma = Float(gamma)

        if gamma.abs > 10.0 || white_point.abs <= 10.0 || white_point.abs < gamma.abs
            gamma, white_point = white_point, gamma
            unless gamma_arg
                white_point = Magick::QuantumRange - black_point
            end
        end

        return level2(black_point, white_point, gamma)
    end

matte_fill_to_border(x, y) click to toggle source

Make transparent any neighbor pixel that is not the border color.

    # File lib/RMagick.rb, line 969
    def matte_fill_to_border(x, y)
        f = copy
        f.opacity = Magick::OpaqueOpacity unless f.matte
        f.matte_flood_fill(border_color, TransparentOpacity,
                           x, y, FillToBorderMethod)
    end

matte_floodfill(x, y) click to toggle source

Make transparent any pixel that matches the color of the pixel at (x,y) and is a neighbor.

    # File lib/RMagick.rb, line 960
    def matte_floodfill(x, y)
        f = copy
        f.opacity = OpaqueOpacity unless f.matte
        target = f.pixel_color(x, y)
        f.matte_flood_fill(target, TransparentOpacity,
                           x, y, FloodfillMethod)
    end

matte_point(x, y) click to toggle source

Make the pixel at (x,y) transparent.

    # File lib/RMagick.rb, line 940
    def matte_point(x, y)
        f = copy
        f.opacity = OpaqueOpacity unless f.matte
        pixel = f.pixel_color(x,y)
        pixel.opacity = TransparentOpacity
        f.pixel_color(x, y, pixel)
        return f
    end

matte_replace(x, y) click to toggle source

Make transparent all pixels that are the same color as the pixel at (x, y).

    # File lib/RMagick.rb, line 951
    def matte_replace(x, y)
        f = copy
        f.opacity = OpaqueOpacity unless f.matte
        target = f.pixel_color(x, y)
        f.transparent(target)
    end

matte_reset!() click to toggle source

Make all pixels transparent.

    # File lib/RMagick.rb, line 977
    def matte_reset!
        self.opacity = Magick::TransparentOpacity
        self
    end

resample(x_res=72.0, y_res=nil) click to toggle source

Corresponds to ImageMagick's -resample option

    # File lib/RMagick.rb, line 983
    def resample(x_res=72.0, y_res=nil)
        y_res ||= x_res
        width = x_res * columns / x_resolution + 0.5
        height = y_res * rows / y_resolution + 0.5
        self.x_resolution = x_res
        self.y_resolution = y_res
        resize(width, height)
    end

resize_to_fill(ncols, nrows=nil, gravity=CenterGravity) click to toggle source

Force an image to exact dimensions without changing the aspect ratio. Resize and crop if necessary. (Thanks to Jerett Taylor!)

    # File lib/RMagick.rb, line 994
    def resize_to_fill(ncols, nrows=nil, gravity=CenterGravity)
        copy.resize_to_fill!(ncols, nrows, gravity)
    end

Also aliased as: crop_resized
resize_to_fill!(ncols, nrows=nil, gravity=CenterGravity) click to toggle source

    # File lib/RMagick.rb, line 998
    def resize_to_fill!(ncols, nrows=nil, gravity=CenterGravity)
        nrows ||= ncols
        if ncols != columns || nrows != rows
            scale = [ncols/columns.to_f, nrows/rows.to_f].max
            resize!(scale*columns+0.5, scale*rows+0.5)
        end
        crop!(gravity, ncols, nrows, true) if ncols != columns || nrows != rows
        self
    end

Also aliased as: crop_resized!
resize_to_fit(cols, rows=nil) click to toggle source

Convenience method to resize retaining the aspect ratio. (Thanks to Robert Manni!)

    # File lib/RMagick.rb, line 1014
    def resize_to_fit(cols, rows=nil)
        rows ||= cols
        change_geometry(Geometry.new(cols, rows)) do |ncols, nrows|
            resize(ncols, nrows)
        end
    end

resize_to_fit!(cols, rows=nil) click to toggle source

    # File lib/RMagick.rb, line 1021
    def resize_to_fit!(cols, rows=nil)
        rows ||= cols
        change_geometry(Geometry.new(cols, rows)) do |ncols, nrows|
            resize!(ncols, nrows)
        end
    end

texture_fill_to_border(x, y, texture) click to toggle source

Replace neighboring pixels to border color with texture pixels

    # File lib/RMagick.rb, line 1035
    def texture_fill_to_border(x, y, texture)
        texture_flood_fill(border_color, texture, x, y, FillToBorderMethod)
    end

texture_floodfill(x, y, texture) click to toggle source

Replace matching neighboring pixels with texture pixels

    # File lib/RMagick.rb, line 1029
    def texture_floodfill(x, y, texture)
        target = pixel_color(x, y)
        texture_flood_fill(target, texture, x, y, FloodfillMethod)
    end

view(x, y, width, height) click to toggle source

Construct a view. If a block is present, yield and pass the view object, otherwise return the view object.

    # File lib/RMagick.rb, line 1041
    def view(x, y, width, height)
        view = View.new(self, x, y, width, height)

        if block_given?
            begin
                yield(view)
            ensure
                view.sync
            end
            return nil
        else
            return view
        end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.