Class | Magick::Image |
In: |
lib/RMagick.rb
|
Parent: | Object |
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 708 708: def annotate(draw, width, height, x, y, text, &block) 709: draw.annotate(self, width, height, x, y, text, &block) 710: self 711: 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 729 729: def color_fill_to_border(x, y, fill) 730: color_flood_fill(border_color, fill, x, y, Magick::FillToBorderMethod) 731: 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 722 722: def color_floodfill(x, y, fill) 723: target = pixel_color(x, y) 724: color_flood_fill(target, fill, x, y, Magick::FloodfillMethod) 725: end
Set the color at x,y
# File lib/RMagick.rb, line 714 714: def color_point(x, y, fill) 715: f = copy 716: f.pixel_color(x, y, fill) 717: return f 718: end
Set all pixels to the fill color. Very similar to Image#erase! Accepts either String or Pixel arguments
# File lib/RMagick.rb, line 735 735: def color_reset!(fill) 736: save = background_color 737: # Change the background color _outside_ the begin block 738: # so that if this object is frozen the exeception will be 739: # raised before we have to handle it explicitly. 740: self.background_color = fill 741: begin 742: erase! 743: ensure 744: self.background_color = save 745: end 746: self 747: 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 751 751: def crop_resized(ncols, nrows, gravity=CenterGravity) 752: copy.crop_resized!(ncols, nrows, gravity) 753: end
# File lib/RMagick.rb, line 755 755: def crop_resized!(ncols, nrows, gravity=CenterGravity) 756: if ncols != columns || nrows != rows 757: scale = [ncols/columns.to_f, nrows/rows.to_f].max 758: resize!(scale*columns+0.5, scale*rows+0.5) 759: end 760: crop!(gravity, ncols, nrows, true) if ncols != columns || nrows != rows 761: self 762: end
Used by ImageList methods - see ImageList#cur_image
# File lib/RMagick.rb, line 765 765: def cur_image 766: self 767: end
Iterate over IPTC record number:dataset tags, yield for each non-nil dataset
# File lib/RMagick.rb, line 817 817: def each_iptc_dataset 818: Magick::IPTC.constants.each do |record| 819: rec = Magick::IPTC.const_get(record) 820: rec.constants.each do |dataset| 821: data_field = get_iptc_dataset(rec.const_get(dataset)) 822: yield(dataset, data_field) unless data_field.nil? 823: end 824: end 825: nil 826: 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 773 773: def get_exif_by_entry(*entry) 774: ary = Array.new 775: if entry.length == 0 776: exif_data = self['EXIF:*'] 777: if exif_data 778: exif_data.split("\n").each { |exif| ary.push(exif.split('=')) } 779: end 780: else 781: entry.each do |name| 782: rval = self["EXIF:#{name}"] 783: ary.push([name, rval]) 784: end 785: end 786: return ary 787: end
Retrieve EXIF data by tag number or all tag/value pairs. The return value is a hash.
# File lib/RMagick.rb, line 790 790: def get_exif_by_number(*tag) 791: hash = Hash.new 792: if tag.length == 0 793: exif_data = self['EXIF:!'] 794: if exif_data 795: exif_data.split("\n").each do |exif| 796: tag, value = exif.split('=') 797: tag = tag[1,4].hex 798: hash[tag] = value 799: end 800: end 801: else 802: tag.each do |num| 803: rval = self["EXIF:#{'#%04X' % num}"] 804: hash[num] = rval == 'unknown' ? nil : rval 805: end 806: end 807: return hash 808: end
Retrieve IPTC information by record number:dataset tag constant defined in Magick::IPTC, above.
# File lib/RMagick.rb, line 812 812: def get_iptc_dataset(ds) 813: self['IPTC:'+ds] 814: end
(Thanks to Al Evans for the suggestion.)
# File lib/RMagick.rb, line 841 841: def level(black_point=0.0, white_point=nil, gamma=nil) 842: black_point = Float(black_point) 843: 844: white_point ||= Magick::MaxRGB - black_point 845: white_point = Float(white_point) 846: 847: gamma_arg = gamma 848: gamma ||= 1.0 849: gamma = Float(gamma) 850: 851: if gamma.abs > 10.0 || white_point.abs <= 10.0 || white_point.abs < gamma.abs 852: gamma, white_point = white_point, gamma 853: unless gamma_arg 854: white_point = Magick::MaxRGB - black_point 855: end 856: end 857: 858: return level2(black_point, white_point, gamma) 859: end
Make transparent any neighbor pixel that is not the border color.
# File lib/RMagick.rb, line 895 895: def matte_fill_to_border(x, y) 896: f = copy 897: f.opacity = Magick::OpaqueOpacity unless f.matte 898: f.matte_flood_fill(border_color, TransparentOpacity, 899: x, y, FillToBorderMethod) 900: end
Make transparent any pixel that matches the color of the pixel at (x,y) and is a neighbor.
# File lib/RMagick.rb, line 886 886: def matte_floodfill(x, y) 887: f = copy 888: f.opacity = OpaqueOpacity unless f.matte 889: target = f.pixel_color(x, y) 890: f.matte_flood_fill(target, TransparentOpacity, 891: x, y, FloodfillMethod) 892: end
Make the pixel at (x,y) transparent.
# File lib/RMagick.rb, line 866 866: def matte_point(x, y) 867: f = copy 868: f.opacity = OpaqueOpacity unless f.matte 869: pixel = f.pixel_color(x,y) 870: pixel.opacity = TransparentOpacity 871: f.pixel_color(x, y, pixel) 872: return f 873: end
Make transparent all pixels that are the same color as the pixel at (x, y).
# File lib/RMagick.rb, line 877 877: def matte_replace(x, y) 878: f = copy 879: f.opacity = OpaqueOpacity unless f.matte 880: target = f.pixel_color(x, y) 881: f.transparent(target) 882: end
Make all pixels transparent.
# File lib/RMagick.rb, line 903 903: def matte_reset! 904: self.opacity = Magick::TransparentOpacity 905: self 906: end
Corresponds to ImageMagick‘s -resample option
# File lib/RMagick.rb, line 909 909: def resample(x_res=72.0, y_res=nil) 910: y_res ||= x_res 911: width = x_res * columns / x_resolution + 0.5 912: height = y_res * rows / y_resolution + 0.5 913: self.x_resolution = x_res 914: self.y_resolution = y_res 915: resize(width, height) 916: end
Convenience method to resize retaining the aspect ratio. (Thanks to Robert Manni!)
# File lib/RMagick.rb, line 920 920: def resize_to_fit(cols, rows) 921: change_geometry(Geometry.new(cols, rows)) do |ncols, nrows| 922: resize(ncols, nrows) 923: end 924: end
# File lib/RMagick.rb, line 926 926: def resize_to_fit!(cols, rows) 927: change_geometry(Geometry.new(cols, rows)) do |ncols, nrows| 928: resize!(ncols, nrows) 929: end 930: end
Replace neighboring pixels to border color with texture pixels
# File lib/RMagick.rb, line 939 939: def texture_fill_to_border(x, y, texture) 940: texture_flood_fill(border_color, texture, x, y, FillToBorderMethod) 941: end
Replace matching neighboring pixels with texture pixels
# File lib/RMagick.rb, line 933 933: def texture_floodfill(x, y, texture) 934: target = pixel_color(x, y) 935: texture_flood_fill(target, texture, x, y, FloodfillMethod) 936: 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 945 945: def view(x, y, width, height) 946: view = View.new(self, x, y, width, height) 947: 948: if block_given? 949: begin 950: yield(view) 951: ensure 952: view.sync 953: end 954: return nil 955: else 956: return view 957: end 958: end