Ruby-level Magick::Image methods
Provide an alternate version of Draw#annotate, for folks who want to find it in this class.
# File lib/RMagick.rb, line 786 786: def annotate(draw, width, height, x, y, text, &block) 787: check_destroyed 788: draw.annotate(self, width, height, x, y, text, &block) 789: self 790: end
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 808: def color_fill_to_border(x, y, fill) 809: color_flood_fill(border_color, fill, x, y, Magick::FillToBorderMethod) 810: end
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 801: def color_floodfill(x, y, fill) 802: target = pixel_color(x, y) 803: color_flood_fill(target, fill, x, y, Magick::FloodfillMethod) 804: end
Set the color at x,y
# File lib/RMagick.rb, line 793 793: def color_point(x, y, fill) 794: f = copy 795: f.pixel_color(x, y, fill) 796: return f 797: end
Set all pixels to the fill color. Very similar to Image#erase! Accepts either String or Pixel arguments
# File lib/RMagick.rb, line 814 814: def color_reset!(fill) 815: save = background_color 816: # Change the background color _outside_ the begin block 817: # so that if this object is frozen the exeception will be 818: # raised before we have to handle it explicitly. 819: self.background_color = fill 820: begin 821: erase! 822: ensure 823: self.background_color = save 824: end 825: self 826: end
Preserve aliases used < RMagick 2.0.1
Used by ImageList methods - see ImageList#cur_image
# File lib/RMagick.rb, line 829 829: def cur_image 830: self 831: end
Iterate over IPTC record number:dataset tags, yield for each non-nil dataset
# File lib/RMagick.rb, line 891 891: def each_iptc_dataset 892: Magick::IPTC.constants.each do |record| 893: rec = Magick::IPTC.const_get(record) 894: rec.constants.each do |dataset| 895: data_field = get_iptc_dataset(rec.const_get(dataset)) 896: yield(dataset, data_field) unless data_field.nil? 897: end 898: end 899: nil 900: end
Thanks to Russell Norris!
# File lib/RMagick.rb, line 834 834: def each_pixel 835: get_pixels(0, 0, columns, rows).each_with_index do |p, n| 836: yield(p, n%columns, n/columns) 837: end 838: self 839: 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.
# File lib/RMagick.rb, line 845 845: def get_exif_by_entry(*entry) 846: ary = Array.new 847: if entry.length == 0 848: exif_data = self['EXIF:*'] 849: if exif_data 850: exif_data.split("\n").each { |exif| ary.push(exif.split('=')) } 851: end 852: else 853: get_exif_by_entry() # ensure properties is populated with exif data 854: entry.each do |name| 855: rval = self["EXIF:#{name}"] 856: ary.push([name, rval]) 857: end 858: end 859: return ary 860: end
Retrieve EXIF data by tag number or all tag/value pairs. The return value is a hash.
# File lib/RMagick.rb, line 863 863: def get_exif_by_number(*tag) 864: hash = Hash.new 865: if tag.length == 0 866: exif_data = self['EXIF:!'] 867: if exif_data 868: exif_data.split("\n").each do |exif| 869: tag, value = exif.split('=') 870: tag = tag[1,4].hex 871: hash[tag] = value 872: end 873: end 874: else 875: get_exif_by_number() # ensure properties is populated with exif data 876: tag.each do |num| 877: rval = self['#%04X' % num.to_i] 878: hash[num] = rval == 'unknown' ? nil : rval 879: end 880: end 881: return hash 882: end
Retrieve IPTC information by record number:dataset tag constant defined in Magick::IPTC, above.
# File lib/RMagick.rb, line 886 886: def get_iptc_dataset(ds) 887: self['IPTC:'+ds] 888: end
(Thanks to Al Evans for the suggestion.)
# File lib/RMagick.rb, line 915 915: def level(black_point=0.0, white_point=nil, gamma=nil) 916: black_point = Float(black_point) 917: 918: white_point ||= Magick::QuantumRange - black_point 919: white_point = Float(white_point) 920: 921: gamma_arg = gamma 922: gamma ||= 1.0 923: gamma = Float(gamma) 924: 925: if gamma.abs > 10.0 || white_point.abs <= 10.0 || white_point.abs < gamma.abs 926: gamma, white_point = white_point, gamma 927: unless gamma_arg 928: white_point = Magick::QuantumRange - black_point 929: end 930: end 931: 932: return level2(black_point, white_point, gamma) 933: end
Make transparent any neighbor pixel that is not the border color.
# File lib/RMagick.rb, line 969 969: def matte_fill_to_border(x, y) 970: f = copy 971: f.opacity = Magick::OpaqueOpacity unless f.matte 972: f.matte_flood_fill(border_color, TransparentOpacity, 973: x, y, FillToBorderMethod) 974: end
Make transparent any pixel that matches the color of the pixel at (x,y) and is a neighbor.
# File lib/RMagick.rb, line 960 960: def matte_floodfill(x, y) 961: f = copy 962: f.opacity = OpaqueOpacity unless f.matte 963: target = f.pixel_color(x, y) 964: f.matte_flood_fill(target, TransparentOpacity, 965: x, y, FloodfillMethod) 966: end
Make the pixel at (x,y) transparent.
# File lib/RMagick.rb, line 940 940: def matte_point(x, y) 941: f = copy 942: f.opacity = OpaqueOpacity unless f.matte 943: pixel = f.pixel_color(x,y) 944: pixel.opacity = TransparentOpacity 945: f.pixel_color(x, y, pixel) 946: return f 947: end
Make transparent all pixels that are the same color as the pixel at (x, y).
# File lib/RMagick.rb, line 951 951: def matte_replace(x, y) 952: f = copy 953: f.opacity = OpaqueOpacity unless f.matte 954: target = f.pixel_color(x, y) 955: f.transparent(target) 956: end
Make all pixels transparent.
# File lib/RMagick.rb, line 977 977: def matte_reset! 978: self.opacity = Magick::TransparentOpacity 979: self 980: end
Corresponds to ImageMagick’s -resample option
# File lib/RMagick.rb, line 983 983: def resample(x_res=72.0, y_res=nil) 984: y_res ||= x_res 985: width = x_res * columns / x_resolution + 0.5 986: height = y_res * rows / y_resolution + 0.5 987: self.x_resolution = x_res 988: self.y_resolution = y_res 989: resize(width, height) 990: end
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 994: def resize_to_fill(ncols, nrows=nil, gravity=CenterGravity) 995: copy.resize_to_fill!(ncols, nrows, gravity) 996: end
# File lib/RMagick.rb, line 998 998: def resize_to_fill!(ncols, nrows=nil, gravity=CenterGravity) 999: nrows ||= ncols 1000: if ncols != columns || nrows != rows 1001: scale = [ncols/columns.to_f, nrows/rows.to_f].max 1002: resize!(scale*columns+0.5, scale*rows+0.5) 1003: end 1004: crop!(gravity, ncols, nrows, true) if ncols != columns || nrows != rows 1005: self 1006: end
Convenience method to resize retaining the aspect ratio. (Thanks to Robert Manni!)
# File lib/RMagick.rb, line 1014 1014: def resize_to_fit(cols, rows=nil) 1015: rows ||= cols 1016: change_geometry(Geometry.new(cols, rows)) do |ncols, nrows| 1017: resize(ncols, nrows) 1018: end 1019: end
# File lib/RMagick.rb, line 1021 1021: def resize_to_fit!(cols, rows=nil) 1022: rows ||= cols 1023: change_geometry(Geometry.new(cols, rows)) do |ncols, nrows| 1024: resize!(ncols, nrows) 1025: end 1026: end
Replace neighboring pixels to border color with texture pixels
# File lib/RMagick.rb, line 1035 1035: def texture_fill_to_border(x, y, texture) 1036: texture_flood_fill(border_color, texture, x, y, FillToBorderMethod) 1037: end
Replace matching neighboring pixels with texture pixels
# File lib/RMagick.rb, line 1029 1029: def texture_floodfill(x, y, texture) 1030: target = pixel_color(x, y) 1031: texture_flood_fill(target, texture, x, y, FloodfillMethod) 1032: end
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 1041: def view(x, y, width, height) 1042: view = View.new(self, x, y, width, height) 1043: 1044: if block_given? 1045: begin 1046: yield(view) 1047: ensure 1048: view.sync 1049: end 1050: return nil 1051: else 1052: return view 1053: end 1054: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.