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 599 599: def annotate(draw, width, height, x, y, text, &block) 600: draw.annotate(self, width, height, x, y, text, &block) 601: self 602: 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 620 620: def color_fill_to_border(x, y, fill) 621: color_flood_fill(border_color, fill, x, y, Magick::FillToBorderMethod) 622: 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 613 613: def color_floodfill(x, y, fill) 614: target = pixel_color(x, y) 615: color_flood_fill(target, fill, x, y, Magick::FloodfillMethod) 616: end
Set the color at x,y
# File lib/RMagick.rb, line 605 605: def color_point(x, y, fill) 606: f = copy 607: f.pixel_color(x, y, fill) 608: return f 609: end
Set all pixels to the fill color. Very similar to Image#erase! Accepts either String or Pixel arguments
# File lib/RMagick.rb, line 626 626: def color_reset!(fill) 627: save = background_color 628: # Change the background color _outside_ the begin block 629: # so that if this object is frozen the exeception will be 630: # raised before we have to handle it explicitly. 631: self.background_color = fill 632: begin 633: erase! 634: ensure 635: self.background_color = save 636: end 637: self 638: 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 642 642: def crop_resized(ncols, nrows, gravity=CenterGravity) 643: copy.crop_resized!(ncols, nrows, gravity) 644: end
# File lib/RMagick.rb, line 646 646: def crop_resized!(ncols, nrows, gravity=CenterGravity) 647: if ncols != columns || nrows != rows 648: scale = [ncols/columns.to_f, nrows/rows.to_f].max 649: resize!(scale*columns+0.5, scale*rows+0.5) 650: end 651: crop!(gravity, ncols, nrows, true) if ncols != columns || nrows != rows 652: self 653: end
Used by ImageList methods - see ImageList#cur_image
# File lib/RMagick.rb, line 656 656: def cur_image 657: self 658: 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 722 722: def get_exif_by_entry(*entry) 723: ary = Array.new 724: if entry.length == 0 725: exif_data = self['EXIF:*'] 726: if exif_data 727: exif_data.split("\n").each { |exif| ary.push(exif.split('=')) } 728: end 729: else 730: entry.each do |name| 731: rval = self["EXIF:#{name}"] 732: ary.push([name, rval]) 733: end 734: end 735: return ary 736: end
Retrieve EXIF data by tag number or all tag/value pairs. The return value is a hash.
# File lib/RMagick.rb, line 739 739: def get_exif_by_number(*tag) 740: hash = Hash.new 741: if tag.length == 0 742: exif_data = self['EXIF:!'] 743: if exif_data 744: exif_data.split("\n").each do |exif| 745: tag, value = exif.split('=') 746: tag = tag[1,4].hex 747: hash[tag] = value 748: end 749: end 750: else 751: tag.each do |num| 752: rval = self["EXIF:#{'#%04X' % num}"] 753: hash[num] = rval == 'unknown' ? nil : rval 754: end 755: end 756: return hash 757: end
Make transparent any neighbor pixel that is not the border color.
# File lib/RMagick.rb, line 694 694: def matte_fill_to_border(x, y) 695: f = copy 696: f.opacity = Magick::OpaqueOpacity unless f.matte 697: f.matte_flood_fill(border_color, TransparentOpacity, 698: x, y, FillToBorderMethod) 699: end
Make transparent any pixel that matches the color of the pixel at (x,y) and is a neighbor.
# File lib/RMagick.rb, line 685 685: def matte_floodfill(x, y) 686: f = copy 687: f.opacity = OpaqueOpacity unless f.matte 688: target = f.pixel_color(x, y) 689: f.matte_flood_fill(target, TransparentOpacity, 690: x, y, FloodfillMethod) 691: end
Make the pixel at (x,y) transparent.
# File lib/RMagick.rb, line 665 665: def matte_point(x, y) 666: f = copy 667: f.opacity = OpaqueOpacity unless f.matte 668: pixel = f.pixel_color(x,y) 669: pixel.opacity = TransparentOpacity 670: f.pixel_color(x, y, pixel) 671: return f 672: end
Make transparent all pixels that are the same color as the pixel at (x, y).
# File lib/RMagick.rb, line 676 676: def matte_replace(x, y) 677: f = copy 678: f.opacity = OpaqueOpacity unless f.matte 679: target = f.pixel_color(x, y) 680: f.transparent(target) 681: end
Make all pixels transparent.
# File lib/RMagick.rb, line 702 702: def matte_reset! 703: self.opacity = Magick::TransparentOpacity 704: self 705: end
Replace neighboring pixels to border color with texture pixels
# File lib/RMagick.rb, line 714 714: def texture_fill_to_border(x, y, texture) 715: texture_flood_fill(border_color, texture, x, y, FillToBorderMethod) 716: end
Replace matching neighboring pixels with texture pixels
# File lib/RMagick.rb, line 708 708: def texture_floodfill(x, y, texture) 709: target = pixel_color(x, y) 710: texture_flood_fill(target, texture, x, y, FloodfillMethod) 711: 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 761 761: def view(x, y, width, height) 762: view = View.new(self, x, y, width, height) 763: 764: if block_given? 765: begin 766: yield(view) 767: ensure 768: view.sync 769: end 770: return nil 771: else 772: return view 773: end 774: end