class Magick::Image
Ruby-level Magick::Image methods
Public Instance Methods
Source
# File lib/rmagick_internal.rb, line 771 def annotate(draw, width, height, x, y, text, &) check_destroyed draw.annotate(self, width, height, x, y, text, &) self end
Provide an alternate version of Draw#annotate, for folks who want to find it in this class.
Source
# File lib/rmagick_internal.rb, line 793 def color_fill_to_border(x, y, fill) color_flood_fill(border_color, fill, x, y, Magick::FillToBorderMethod) end
Set all pixels that are neighbors of x,y and are not the border color to the fill color
Source
# File lib/rmagick_internal.rb, line 786 def color_floodfill(x, y, fill) target = pixel_color(x, y) color_flood_fill(target, fill, x, y, Magick::FloodfillMethod) end
Set all pixels that have the same color as the pixel at x,y and are neighbors to the fill color
Source
# File lib/rmagick_internal.rb, line 778 def color_point(x, y, fill) f = copy f.pixel_color(x, y, fill) f end
Set the color at x,y
Source
# File lib/rmagick_internal.rb, line 799 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
Set all pixels to the fill color. Very similar to Image#erase! Accepts either String or Pixel arguments
Preserve aliases used < RMagick 2.0.1
Source
# File lib/rmagick_internal.rb, line 814 def cur_image self end
Used by ImageList methods - see ImageList#cur_image
Source
# File lib/rmagick_internal.rb, line 872 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
Iterate over IPTC record number:dataset tags, yield for each non-nil dataset
Source
# File lib/rmagick_internal.rb, line 819 def each_pixel get_pixels(0, 0, columns, rows).each_with_index do |p, n| yield(p, n % columns, n / columns) end self end
Thanks to Russell Norris!
Source
# File lib/rmagick_internal.rb, line 830 def get_exif_by_entry(*entry) ary = [] if entry.empty? exif_data = self['EXIF:*'] exif_data&.split("\n")&.each { |exif| ary.push(exif.split('=')) } 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 ary end
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.
Source
# File lib/rmagick_internal.rb, line 846 def get_exif_by_number(*tag) hash = {} if tag.empty? exif_data = self['EXIF:!'] exif_data&.split("\n")&.each do |exif| tag, value = exif.split('=') tag = tag[1, 4].hex hash[tag] = value end else get_exif_by_number # ensure properties is populated with exif data tag.each do |num| rval = self[sprintf('#%04X', num.to_i)] hash[num] = rval == 'unknown' ? nil : rval end end hash end
Retrieve EXIF data by tag number or all tag/value pairs. The return value is a hash.
Source
# File lib/rmagick_internal.rb, line 867 def get_iptc_dataset(ds) self['IPTC:' + ds] end
Retrieve IPTC information by record number:dataset tag constant defined in Magick::IPTC, above.
Source
# File lib/rmagick_internal.rb, line 896 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 white_point = Magick::QuantumRange - black_point unless gamma_arg end level2(black_point, white_point, gamma) end
(Thanks to Al Evans for the suggestion.)
Source
# File lib/rmagick_internal.rb, line 947 def matte_fill_to_border(x, y) f = copy f.alpha(OpaqueAlphaChannel) unless f.alpha? f.matte_flood_fill(border_color, x, y, FillToBorderMethod, alpha: TransparentAlpha) end
Make transparent any neighbor pixel that is not the border color.
Source
# File lib/rmagick_internal.rb, line 939 def matte_floodfill(x, y) f = copy f.alpha(OpaqueAlphaChannel) unless f.alpha? target = f.pixel_color(x, y) f.matte_flood_fill(target, x, y, FloodfillMethod, alpha: TransparentAlpha) end
Make transparent any pixel that matches the color of the pixel at (x,y) and is a neighbor.
Source
# File lib/rmagick_internal.rb, line 919 def matte_point(x, y) f = copy f.alpha(OpaqueAlphaChannel) unless f.alpha? pixel = f.pixel_color(x, y) pixel.alpha = TransparentAlpha f.pixel_color(x, y, pixel) f end
Make the pixel at (x,y) transparent.
Source
# File lib/rmagick_internal.rb, line 930 def matte_replace(x, y) f = copy f.alpha(OpaqueAlphaChannel) unless f.alpha? target = f.pixel_color(x, y) f.transparent(target) end
Make transparent all pixels that are the same color as the pixel at (x, y).
Source
# File lib/rmagick_internal.rb, line 954 def matte_reset! alpha(TransparentAlphaChannel) self end
Make all pixels transparent.
Source
# File lib/rmagick_internal.rb, line 961 def resize_to_fill(ncols, nrows = nil, gravity = CenterGravity) copy.resize_to_fill!(ncols, nrows, gravity) end
Force an image to exact dimensions without changing the aspect ratio. Resize and crop if necessary. (Thanks to Jerett Taylor!)
Source
# File lib/rmagick_internal.rb, line 965 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
Source
# File lib/rmagick_internal.rb, line 981 def resize_to_fit(cols, rows = nil) rows ||= cols change_geometry(Geometry.new(cols, rows)) do |ncols, nrows| resize(ncols, nrows) end end
Convenience method to resize retaining the aspect ratio. (Thanks to Robert Manni!)
Source
# File lib/rmagick_internal.rb, line 988 def resize_to_fit!(cols, rows = nil) rows ||= cols change_geometry(Geometry.new(cols, rows)) do |ncols, nrows| resize!(ncols, nrows) end end
Source
# File lib/rmagick_internal.rb, line 1002 def texture_fill_to_border(x, y, texture) texture_flood_fill(border_color, texture, x, y, FillToBorderMethod) end
Replace neighboring pixels to border color with texture pixels
Source
# File lib/rmagick_internal.rb, line 996 def texture_floodfill(x, y, texture) target = pixel_color(x, y) texture_flood_fill(target, texture, x, y, FloodfillMethod) end
Replace matching neighboring pixels with texture pixels
Source
# File lib/rmagick_internal.rb, line 1008 def view(x, y, width, height) view = View.new(self, x, y, width, height) return view unless block_given? begin yield(view) ensure view.sync end nil end
Construct a view. If a block is present, yield and pass the view object, otherwise return the view object.