class Magick::Image
Ruby-level Magick::Image methods
def annotate(draw, width, height, x, y, text, &block)
Provide an alternate version of Draw#annotate, for folks who
def annotate(draw, width, height, x, y, text, &block) check_destroyed draw.annotate(self, width, height, x, y, text, &block) self end
def color_fill_to_border(x, y, fill)
Set all pixels that are neighbors of x,y and are not the border color
def color_fill_to_border(x, y, fill) color_flood_fill(border_color, fill, x, y, Magick::FillToBorderMethod) end
def color_floodfill(x, y, fill)
Set all pixels that have the same color as the pixel at x,y and
def color_floodfill(x, y, fill) target = pixel_color(x, y) color_flood_fill(target, fill, x, y, Magick::FloodfillMethod) end
def color_point(x, y, fill)
def color_point(x, y, fill) f = copy f.pixel_color(x, y, fill) return f end
def color_reset!(fill)
Set all pixels to the fill color. Very similar to Image#erase!
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
def cur_image
def cur_image self end
def each_iptc_dataset
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
def each_pixel
def each_pixel get_pixels(0, 0, columns, rows).each_with_index do |p, n| yield(p, n%columns, n/columns) end self end
def get_exif_by_entry(*entry)
return all entries and values. The return value is an array of [name,value]
return the values associated with the entries. If no entries specified,
Retrieve EXIF data by entry or all. If one or more entry names specified,
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
def get_exif_by_number(*tag)
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
def get_iptc_dataset(ds)
Retrieve IPTC information by record number:dataset tag constant defined in
def get_iptc_dataset(ds) self['IPTC:'+ds] end
def level(black_point=0.0, white_point=nil, gamma=nil)
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
def matte_fill_to_border(x, y)
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
def matte_floodfill(x, y)
Make transparent any pixel that matches the color of the pixel
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
def matte_point(x, y)
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
def matte_replace(x, y)
Make transparent all pixels that are the same color as the
def matte_replace(x, y) f = copy f.opacity = OpaqueOpacity unless f.matte target = f.pixel_color(x, y) f.transparent(target) end
def matte_reset!
def matte_reset! self.opacity = Magick::TransparentOpacity self end
def resample(x_res=72.0, y_res=nil)
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
def resize_to_fill(ncols, nrows=nil, gravity=CenterGravity)
Force an image to exact dimensions without changing the aspect ratio.
def resize_to_fill(ncols, nrows=nil, gravity=CenterGravity) copy.resize_to_fill!(ncols, nrows, gravity) end
def resize_to_fill!(ncols, nrows=nil, gravity=CenterGravity)
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
def resize_to_fit(cols, rows=nil)
Convenience method to resize retaining the aspect ratio.
def resize_to_fit(cols, rows=nil) rows ||= cols change_geometry(Geometry.new(cols, rows)) do |ncols, nrows| resize(ncols, nrows) end end
def resize_to_fit!(cols, rows=nil)
def resize_to_fit!(cols, rows=nil) rows ||= cols change_geometry(Geometry.new(cols, rows)) do |ncols, nrows| resize!(ncols, nrows) end end
def texture_fill_to_border(x, y, texture)
def texture_fill_to_border(x, y, texture) texture_flood_fill(border_color, texture, x, y, FillToBorderMethod) end
def texture_floodfill(x, y, texture)
def texture_floodfill(x, y, texture) target = pixel_color(x, y) texture_flood_fill(target, texture, x, y, FloodfillMethod) end
def view(x, y, width, height)
Construct a view. If a block is present, yield and pass the view
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