Class Magick::Image
In: lib/RMagick.rb
Parent: Object
Enum GeometryValue Stylable RVG\n[lib/rvg/clippath.rb\nlib/rvg/container.rb\nlib/rvg/deep_equal.rb\nlib/rvg/describable.rb\nlib/rvg/embellishable.rb\nlib/rvg/misc.rb\nlib/rvg/paint.rb\nlib/rvg/pathdata.rb\nlib/rvg/rvg.rb\nlib/rvg/stretchable.rb\nlib/rvg/stylable.rb\nlib/rvg/text.rb\nlib/rvg/transformable.rb\nlib/rvg/units.rb] Transformable Stretchable Embellishable Describable Duplicatable Comparable Image ImageList Enumerable Geometry OptionalMethodArguments HatchFill Draw lib/RMagick.rb lib/rvg/misc.rb ObjectData Application Pre_ObjectData_Descriptor Envelope Post_ObjectData_Descriptor IPTC Magick dot/m_14_0.png

Ruby-level Magick::Image methods

Methods

Included Modules

Comparable

Classes and Modules

Class Magick::Image::View

External Aliases

remap -> affinity

Public Instance methods

Provide an alternate version of Draw#annotate, for folks who want to find it in this class.

[Source]

     # File lib/RMagick.rb, line 772
772:     def annotate(draw, width, height, x, y, text, &block)
773:       check_destroyed
774:       draw.annotate(self, width, height, x, y, text, &block)
775:       self
776:     end

Set all pixels that are neighbors of x,y and are not the border color to the fill color

[Source]

     # File lib/RMagick.rb, line 794
794:     def color_fill_to_border(x, y, fill)
795:         color_flood_fill(border_color, fill, x, y, Magick::FillToBorderMethod)
796:     end

Set all pixels that have the same color as the pixel at x,y and are neighbors to the fill color

[Source]

     # File lib/RMagick.rb, line 787
787:     def color_floodfill(x, y, fill)
788:         target = pixel_color(x, y)
789:         color_flood_fill(target, fill, x, y, Magick::FloodfillMethod)
790:     end

Set the color at x,y

[Source]

     # File lib/RMagick.rb, line 779
779:     def color_point(x, y, fill)
780:         f = copy
781:         f.pixel_color(x, y, fill)
782:         return f
783:     end

Set all pixels to the fill color. Very similar to Image#erase! Accepts either String or Pixel arguments

[Source]

     # File lib/RMagick.rb, line 800
800:     def color_reset!(fill)
801:         save = background_color
802:         # Change the background color _outside_ the begin block
803:         # so that if this object is frozen the exeception will be
804:         # raised before we have to handle it explicitly.
805:         self.background_color = fill
806:         begin
807:             erase!
808:         ensure
809:             self.background_color = save
810:         end
811:         self
812:     end
crop_resized(ncols, nrows=nil, gravity=CenterGravity)

Alias for resize_to_fill

crop_resized!(ncols, nrows=nil, gravity=CenterGravity)

Alias for resize_to_fill!

Used by ImageList methods - see ImageList#cur_image

[Source]

     # File lib/RMagick.rb, line 815
815:     def cur_image
816:         self
817:     end

Iterate over IPTC record number:dataset tags, yield for each non-nil dataset

[Source]

     # File lib/RMagick.rb, line 877
877:     def each_iptc_dataset
878:         Magick::IPTC.constants.each do |record|
879:             rec = Magick::IPTC.const_get(record)
880:             rec.constants.each do |dataset|
881:                 data_field = get_iptc_dataset(rec.const_get(dataset))
882:                 yield(dataset, data_field) unless data_field.nil?
883:             end
884:         end
885:         nil
886:     end

Thanks to Russell Norris!

[Source]

     # File lib/RMagick.rb, line 820
820:     def each_pixel
821:       get_pixels(0, 0, columns, rows).each_with_index do |p, n|
822:         yield(p, n%columns, n/columns)
823:       end
824:       self
825:     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.

[Source]

     # File lib/RMagick.rb, line 831
831:     def get_exif_by_entry(*entry)
832:         ary = Array.new
833:         if entry.length == 0
834:             exif_data = self['EXIF:*']
835:             if exif_data
836:                 exif_data.split("\n").each { |exif| ary.push(exif.split('=')) }
837:             end
838:         else
839:             get_exif_by_entry()     # ensure properties is populated with exif data
840:             entry.each do |name|
841:                 rval = self["EXIF:#{name}"]
842:                 ary.push([name, rval])
843:             end
844:         end
845:         return ary
846:     end

Retrieve EXIF data by tag number or all tag/value pairs. The return value is a hash.

[Source]

     # File lib/RMagick.rb, line 849
849:     def get_exif_by_number(*tag)
850:         hash = Hash.new
851:         if tag.length == 0
852:             exif_data = self['EXIF:!']
853:             if exif_data
854:                 exif_data.split("\n").each do |exif|
855:                     tag, value = exif.split('=')
856:                     tag = tag[1,4].hex
857:                     hash[tag] = value
858:                 end
859:             end
860:         else
861:             get_exif_by_number()    # ensure properties is populated with exif data
862:             tag.each do |num|
863:                 rval = self['#%04X' % num.to_i]
864:                 hash[num] = rval == 'unknown' ? nil : rval
865:             end
866:         end
867:         return hash
868:     end

Retrieve IPTC information by record number:dataset tag constant defined in Magick::IPTC, above.

[Source]

     # File lib/RMagick.rb, line 872
872:     def get_iptc_dataset(ds)
873:         self['IPTC:'+ds]
874:     end

(Thanks to Al Evans for the suggestion.)

[Source]

     # File lib/RMagick.rb, line 901
901:     def level(black_point=0.0, white_point=nil, gamma=nil)
902:         black_point = Float(black_point)
903: 
904:         white_point ||= Magick::QuantumRange - black_point
905:         white_point = Float(white_point)
906: 
907:         gamma_arg = gamma
908:         gamma ||= 1.0
909:         gamma = Float(gamma)
910: 
911:         if gamma.abs > 10.0 || white_point.abs <= 10.0 || white_point.abs < gamma.abs
912:             gamma, white_point = white_point, gamma
913:             unless gamma_arg
914:                 white_point = Magick::QuantumRange - black_point
915:             end
916:         end
917: 
918:         return level2(black_point, white_point, gamma)
919:     end

Make transparent any neighbor pixel that is not the border color.

[Source]

     # File lib/RMagick.rb, line 955
955:     def matte_fill_to_border(x, y)
956:         f = copy
957:         f.opacity = Magick::OpaqueOpacity unless f.matte
958:         f.matte_flood_fill(border_color, TransparentOpacity,
959:                            x, y, FillToBorderMethod)
960:     end

Make transparent any pixel that matches the color of the pixel at (x,y) and is a neighbor.

[Source]

     # File lib/RMagick.rb, line 946
946:     def matte_floodfill(x, y)
947:         f = copy
948:         f.opacity = OpaqueOpacity unless f.matte
949:         target = f.pixel_color(x, y)
950:         f.matte_flood_fill(target, TransparentOpacity,
951:                            x, y, FloodfillMethod)
952:     end

Make the pixel at (x,y) transparent.

[Source]

     # File lib/RMagick.rb, line 926
926:     def matte_point(x, y)
927:         f = copy
928:         f.opacity = OpaqueOpacity unless f.matte
929:         pixel = f.pixel_color(x,y)
930:         pixel.opacity = TransparentOpacity
931:         f.pixel_color(x, y, pixel)
932:         return f
933:     end

Make transparent all pixels that are the same color as the pixel at (x, y).

[Source]

     # File lib/RMagick.rb, line 937
937:     def matte_replace(x, y)
938:         f = copy
939:         f.opacity = OpaqueOpacity unless f.matte
940:         target = f.pixel_color(x, y)
941:         f.transparent(target)
942:     end

Make all pixels transparent.

[Source]

     # File lib/RMagick.rb, line 963
963:     def matte_reset!
964:         self.opacity = Magick::TransparentOpacity
965:         self
966:     end

Corresponds to ImageMagick‘s -resample option

[Source]

     # File lib/RMagick.rb, line 969
969:     def resample(x_res=72.0, y_res=nil)
970:         y_res ||= x_res
971:         width = x_res * columns / x_resolution + 0.5
972:         height = y_res * rows / y_resolution + 0.5
973:         self.x_resolution = x_res
974:         self.y_resolution = y_res
975:         resize(width, height)
976:     end

Force an image to exact dimensions without changing the aspect ratio. Resize and crop if necessary. (Thanks to Jerett Taylor!)

[Source]

     # File lib/RMagick.rb, line 980
980:     def resize_to_fill(ncols, nrows=nil, gravity=CenterGravity)
981:         copy.resize_to_fill!(ncols, nrows, gravity)
982:     end

[Source]

     # File lib/RMagick.rb, line 984
984:     def resize_to_fill!(ncols, nrows=nil, gravity=CenterGravity)
985:         nrows ||= ncols
986:         if ncols != columns || nrows != rows
987:             scale = [ncols/columns.to_f, nrows/rows.to_f].max
988:             resize!(scale*columns+0.5, scale*rows+0.5)
989:         end
990:         crop!(gravity, ncols, nrows, true) if ncols != columns || nrows != rows
991:         self
992:     end

Convenience method to resize retaining the aspect ratio. (Thanks to Robert Manni!)

[Source]

      # File lib/RMagick.rb, line 1000
1000:     def resize_to_fit(cols, rows=nil)
1001:         rows ||= cols
1002:         change_geometry(Geometry.new(cols, rows)) do |ncols, nrows|
1003:             resize(ncols, nrows)
1004:         end
1005:     end

[Source]

      # File lib/RMagick.rb, line 1007
1007:     def resize_to_fit!(cols, rows=nil)
1008:         rows ||= cols
1009:         change_geometry(Geometry.new(cols, rows)) do |ncols, nrows|
1010:             resize!(ncols, nrows)
1011:         end
1012:     end

Replace neighboring pixels to border color with texture pixels

[Source]

      # File lib/RMagick.rb, line 1021
1021:     def texture_fill_to_border(x, y, texture)
1022:         texture_flood_fill(border_color, texture, x, y, FillToBorderMethod)
1023:     end

Replace matching neighboring pixels with texture pixels

[Source]

      # File lib/RMagick.rb, line 1015
1015:     def texture_floodfill(x, y, texture)
1016:         target = pixel_color(x, y)
1017:         texture_flood_fill(target, texture, x, y, FloodfillMethod)
1018:     end

Construct a view. If a block is present, yield and pass the view object, otherwise return the view object.

[Source]

      # File lib/RMagick.rb, line 1027
1027:     def view(x, y, width, height)
1028:         view = View.new(self, x, y, width, height)
1029: 
1030:         if block_given?
1031:             begin
1032:                 yield(view)
1033:             ensure
1034:                 view.sync
1035:             end
1036:             return nil
1037:         else
1038:             return view
1039:         end
1040:     end

[Validate]