| 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 664
664: def get_exif_by_entry(*entry)
665: ary = Array.new
666: if entry.length == 0
667: exif_data = self['EXIF:*']
668: if exif_data
669: exif_data.split("\n").each { |exif| ary.push(exif.split('=')) }
670: end
671: else
672: entry.each do |name|
673: rval = self["EXIF:#{name}"]
674: ary.push([name, rval])
675: end
676: end
677: return ary
678: end
Retrieve EXIF data by tag number or all tag/value pairs. The return value is a hash.
# File lib/RMagick.rb, line 681
681: def get_exif_by_number(*tag)
682: hash = Hash.new
683: if tag.length == 0
684: exif_data = self['EXIF:!']
685: if exif_data
686: exif_data.split("\n").each do |exif|
687: tag, value = exif.split('=')
688: tag = tag[1,4].hex
689: hash[tag] = value
690: end
691: end
692: else
693: tag.each do |num|
694: rval = self["EXIF:#{'#%04X' % num}"]
695: hash[num] = rval == 'unknown' ? nil : rval
696: end
697: end
698: return hash
699: end
(Thanks to Al Evans for the suggestion.)
# File lib/RMagick.rb, line 714
714: def level(black_point=0.0, white_point=nil, gamma=nil)
715: black_point = Float(black_point)
716:
717: white_point ||= Magick::MaxRGB - black_point
718: white_point = Float(white_point)
719:
720: gamma_arg = gamma
721: gamma ||= 1.0
722: gamma = Float(gamma)
723:
724: if gamma.abs > 10.0 || white_point.abs <= 10.0 || white_point.abs < gamma.abs
725: gamma, white_point = white_point, gamma
726: unless gamma_arg
727: white_point = Magick::MaxRGB - black_point
728: end
729: end
730:
731: return level2(black_point, white_point, gamma)
732: end
Make transparent any neighbor pixel that is not the border color.
# File lib/RMagick.rb, line 768
768: def matte_fill_to_border(x, y)
769: f = copy
770: f.opacity = Magick::OpaqueOpacity unless f.matte
771: f.matte_flood_fill(border_color, TransparentOpacity,
772: x, y, FillToBorderMethod)
773: end
Make transparent any pixel that matches the color of the pixel at (x,y) and is a neighbor.
# File lib/RMagick.rb, line 759
759: def matte_floodfill(x, y)
760: f = copy
761: f.opacity = OpaqueOpacity unless f.matte
762: target = f.pixel_color(x, y)
763: f.matte_flood_fill(target, TransparentOpacity,
764: x, y, FloodfillMethod)
765: end
Make the pixel at (x,y) transparent.
# File lib/RMagick.rb, line 739
739: def matte_point(x, y)
740: f = copy
741: f.opacity = OpaqueOpacity unless f.matte
742: pixel = f.pixel_color(x,y)
743: pixel.opacity = TransparentOpacity
744: f.pixel_color(x, y, pixel)
745: return f
746: end
Make transparent all pixels that are the same color as the pixel at (x, y).
# File lib/RMagick.rb, line 750
750: def matte_replace(x, y)
751: f = copy
752: f.opacity = OpaqueOpacity unless f.matte
753: target = f.pixel_color(x, y)
754: f.transparent(target)
755: end
Make all pixels transparent.
# File lib/RMagick.rb, line 776
776: def matte_reset!
777: self.opacity = Magick::TransparentOpacity
778: self
779: end
Convenience method to resize retaining the aspect ratio. (Thanks to Robert Manni!)
# File lib/RMagick.rb, line 783
783: def resize_to_fit(cols, rows)
784: change_geometry(Geometry.new(cols, rows)) do |ncols, nrows|
785: resize(ncols, nrows)
786: end
787: end
# File lib/RMagick.rb, line 789
789: def resize_to_fit!(cols, rows)
790: change_geometry(Geometry.new(cols, rows)) do |ncols, nrows|
791: resize!(ncols, nrows)
792: end
793: end
Replace neighboring pixels to border color with texture pixels
# File lib/RMagick.rb, line 802
802: def texture_fill_to_border(x, y, texture)
803: texture_flood_fill(border_color, texture, x, y, FillToBorderMethod)
804: end
Replace matching neighboring pixels with texture pixels
# File lib/RMagick.rb, line 796
796: def texture_floodfill(x, y, texture)
797: target = pixel_color(x, y)
798: texture_flood_fill(target, texture, x, y, FloodfillMethod)
799: 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 808
808: def view(x, y, width, height)
809: view = View.new(self, x, y, width, height)
810:
811: if block_given?
812: begin
813: yield(view)
814: ensure
815: view.sync
816: end
817: return nil
818: else
819: return view
820: end
821: end