Class: Magick::Image

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/RMagick.rb,
ext/RMagick/rmmain.c

Overview

Ruby-level Magick::Image methods

Defined Under Namespace

Classes: DrawOptions, Info, PolaroidOptions, View

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeObject

Class Method Details

._loadObject

.captureObject

.combineObject

.constituteObject

.from_blobObject

.pingObject

.readObject

.read_inlineObject

Instance Method Details

#<=>Object

#[]Object

#[]=Object

#_dumpObject

#adaptive_blurObject

do not document! Only used by Image#iterations=

#adaptive_blur_channelObject

#adaptive_resizeObject

#adaptive_sharpenObject

#adaptive_sharpen_channelObject

#adaptive_thresholdObject

#add_compose_maskObject

#add_noiseObject

#add_noise_channelObject

#add_profileObject

#affine_transformObject

#alphaObject

#alpha?Boolean

Returns:

  • (Boolean)

#annotate(draw, width, height, x, y, text, &block) ⇒ Object

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



765
766
767
768
769
# File 'lib/RMagick.rb', line 765

def annotate(draw, width, height, x, y, text, &block)
  check_destroyed
  draw.annotate(self, width, height, x, y, text, &block)
  self
end

#auto_orientObject

#auto_orient!Object

#bilevel_channelObject

#black_thresholdObject

#blendObject

#blur_channelObject

#blur_imageObject

#borderObject

#border!Object

#change_geometryObject

#change_geometry!Object

#changed?Boolean

Returns:

  • (Boolean)

#channelObject

#channel_compareObject

An alias for compare_channel

#channel_depthObject

#channel_extremaObject

#channel_meanObject

#charcoalObject

#check_destroyedObject

#chopObject

#cloneObject

#clut_channelObject

#color_fill_to_border(x, y, fill) ⇒ Object

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



787
788
789
# File 'lib/RMagick.rb', line 787

def color_fill_to_border(x, y, fill)
    color_flood_fill(border_color, fill, x, y, Magick::FillToBorderMethod)
end

#color_flood_fillObject

#color_floodfill(x, y, fill) ⇒ Object

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



780
781
782
783
# File 'lib/RMagick.rb', line 780

def color_floodfill(x, y, fill)
    target = pixel_color(x, y)
    color_flood_fill(target, fill, x, y, Magick::FloodfillMethod)
end

#color_histogramObject

#color_point(x, y, fill) ⇒ Object

Set the color at x,y



772
773
774
775
776
# File 'lib/RMagick.rb', line 772

def color_point(x, y, fill)
    f = copy
    f.pixel_color(x, y, fill)
    return f
end

#color_reset!(fill) ⇒ Object

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



793
794
795
796
797
798
799
800
801
802
803
804
805
# File 'lib/RMagick.rb', line 793

def color_reset!(fill)
    save = background_color
    # Change the background color _outside_ the begin block
    # so that if this object is frozen the exeception will be
    # raised before we have to handle it explicitly.
    self.background_color = fill
    begin
        erase!
    ensure
        self.background_color = save
    end
    self
end

#colorizeObject

#colormapObject

#compare_channelObject

#compositeObject

#composite!Object

#composite_affineObject

#composite_channelObject

#composite_channel!Object

#composite_tiledObject

#composite_tiled!Object

#compress_colormap!Object

#contrastObject

#contrast_stretch_channelObject

#convolveObject

#convolve_channelObject

#copyObject

#cropObject

#crop!Object

#cur_imageObject

Used by ImageList methods - see ImageList#cur_image



808
809
810
# File 'lib/RMagick.rb', line 808

def cur_image
    self
end

#cycle_colormapObject

#decipherObject

#defineObject

#delete_compose_maskObject

#delete_profileObject

#deskewObject

#despeckleObject

#destroy!Object

#destroyed?Boolean

Returns:

  • (Boolean)

#differenceObject

#dispatchObject

#displaceObject

#displayObject Also known as: __display__

#dissolveObject

#distortObject

#distortion_channelObject

#dupObject

#each_iptc_datasetObject

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



870
871
872
873
874
875
876
877
878
879
# File 'lib/RMagick.rb', line 870

def each_iptc_dataset
    Magick::IPTC.constants.each do |record|
        rec = Magick::IPTC.const_get(record)
        rec.constants.each do |dataset|
            data_field = get_iptc_dataset(rec.const_get(dataset))
            yield(dataset, data_field) unless data_field.nil?
        end
    end
    nil
end

#each_pixelObject

Thanks to Russell Norris!



813
814
815
816
817
818
# File 'lib/RMagick.rb', line 813

def each_pixel
  get_pixels(0, 0, columns, rows).each_with_index do |p, n|
    yield(p, n%columns, n/columns)
  end
  self
end

#each_profileObject

#edgeObject

#embossObject

#encipherObject

#enhanceObject

#equalizeObject

#equalize_channelObject

#erase!Object

#excerptObject

#excerpt!Object

#export_pixelsObject

#export_pixels_to_strObject

#extentObject

#find_similar_regionObject

#flipObject

#flip!Object

#flopObject

#flop!Object

#frameObject

#gamma_channelObject

#gamma_correctObject

#gaussian_blurObject

#gaussian_blur_channelObject

#get_exif_by_entry(*entry) ⇒ Object

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.



824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
# File 'lib/RMagick.rb', line 824

def get_exif_by_entry(*entry)
    ary = Array.new
    if entry.length == 0
        exif_data = self['EXIF:*']
        if exif_data
            exif_data.split("\n").each { |exif| ary.push(exif.split('=')) }
        end
    else
        get_exif_by_entry()     # ensure properties is populated with exif data
        entry.each do |name|
            rval = self["EXIF:#{name}"]
            ary.push([name, rval])
        end
    end
    return ary
end

#get_exif_by_number(*tag) ⇒ Object

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



842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
# File 'lib/RMagick.rb', line 842

def get_exif_by_number(*tag)
    hash = Hash.new
    if tag.length == 0
        exif_data = self['EXIF:!']
        if exif_data
            exif_data.split("\n").each do |exif|
                tag, value = exif.split('=')
                tag = tag[1,4].hex
                hash[tag] = value
            end
        end
    else
        get_exif_by_number()    # ensure properties is populated with exif data
        tag.each do |num|
            rval = self['#%04X' % num.to_i]
            hash[num] = rval == 'unknown' ? nil : rval
        end
    end
    return hash
end

#get_iptc_dataset(ds) ⇒ Object

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



865
866
867
# File 'lib/RMagick.rb', line 865

def get_iptc_dataset(ds)
    self['IPTC:'+ds]
end

#get_pixelsObject

#gray?Boolean

Returns:

  • (Boolean)

#grey?Boolean

Returns:

  • (Boolean)

#histogram?Boolean

Returns:

  • (Boolean)

#implodeObject

#import_pixelsObject

#initialize_copyObject

#inspectObject

#level(black_point = 0.0, white_point = nil, gamma = nil) ⇒ Object

(Thanks to Al Evans for the suggestion.)



894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
# File 'lib/RMagick.rb', line 894

def level(black_point=0.0, white_point=nil, gamma=nil)
    black_point = Float(black_point)

    white_point ||= Magick::QuantumRange - black_point
    white_point = Float(white_point)

    gamma_arg = gamma
    gamma ||= 1.0
    gamma = Float(gamma)

    if gamma.abs > 10.0 || white_point.abs <= 10.0 || white_point.abs < gamma.abs
        gamma, white_point = white_point, gamma
        unless gamma_arg
            white_point = Magick::QuantumRange - black_point
        end
    end

    return level2(black_point, white_point, gamma)
end

#level2Object

#level_channelObject

#level_colorsObject

#levelize_channelObject

#linear_stretchObject

#liquid_rescaleObject

#magnifyObject

#magnify!Object

#mapObject

#marshal_dumpObject

#marshal_loadObject

#maskObject

#matte_fill_to_border(x, y) ⇒ Object

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



948
949
950
951
952
953
# File 'lib/RMagick.rb', line 948

def matte_fill_to_border(x, y)
    f = copy
    f.opacity = Magick::OpaqueOpacity unless f.matte
    f.matte_flood_fill(border_color, TransparentOpacity,
                       x, y, FillToBorderMethod)
end

#matte_flood_fillObject

#matte_floodfill(x, y) ⇒ Object

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



939
940
941
942
943
944
945
# File 'lib/RMagick.rb', line 939

def matte_floodfill(x, y)
    f = copy
    f.opacity = OpaqueOpacity unless f.matte
    target = f.pixel_color(x, y)
    f.matte_flood_fill(target, TransparentOpacity,
                       x, y, FloodfillMethod)
end

#matte_point(x, y) ⇒ Object

Make the pixel at (x,y) transparent.



919
920
921
922
923
924
925
926
# File 'lib/RMagick.rb', line 919

def matte_point(x, y)
    f = copy
    f.opacity = OpaqueOpacity unless f.matte
    pixel = f.pixel_color(x,y)
    pixel.opacity = TransparentOpacity
    f.pixel_color(x, y, pixel)
    return f
end

#matte_replace(x, y) ⇒ Object

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



930
931
932
933
934
935
# File 'lib/RMagick.rb', line 930

def matte_replace(x, y)
    f = copy
    f.opacity = OpaqueOpacity unless f.matte
    target = f.pixel_color(x, y)
    f.transparent(target)
end

#matte_reset!Object

Make all pixels transparent.



956
957
958
959
# File 'lib/RMagick.rb', line 956

def matte_reset!
    self.opacity = Magick::TransparentOpacity
    self
end

#median_filterObject

#minifyObject

#minify!Object

#modulateObject

#monochrome?Boolean

Returns:

  • (Boolean)

#motion_blurObject

#negateObject

#negate_channelObject

#normalizeObject

#normalize_channelObject

#oil_paintObject

#opaqueObject

#opaque?Boolean

Returns:

  • (Boolean)

#opaque_channelObject

#ordered_ditherObject

#paint_transparentObject

#palette?Boolean

Returns:

  • (Boolean)

#pixel_colorObject

#polaroidObject

#posterizeObject

#previewObject

rb_define_method(Class_Image, “plasma”, Image_plasma, 6);

#profile!Object

#propertiesObject

#quantizeObject

#quantum_operatorObject

#radial_blurObject

#radial_blur_channelObject

#raiseObject

#random_threshold_channelObject

#recolorObject

#reduce_noiseObject

#remapObject Also known as: affinity

#resample(x_res = 72.0, y_res = nil) ⇒ Object

Corresponds to ImageMagick’s -resample option



962
963
964
965
966
967
968
969
# File 'lib/RMagick.rb', line 962

def resample(x_res=72.0, y_res=nil)
    y_res ||= x_res
    width = x_res * columns / x_resolution + 0.5
    height = y_res * rows / y_resolution + 0.5
    self.x_resolution = x_res
    self.y_resolution = y_res
    resize(width, height)
end

#resizeObject

#resize!Object

#resize_to_fill(ncols, nrows = nil, gravity = CenterGravity) ⇒ Object Also known as: crop_resized

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



973
974
975
# File 'lib/RMagick.rb', line 973

def resize_to_fill(ncols, nrows=nil, gravity=CenterGravity)
    copy.resize_to_fill!(ncols, nrows, gravity)
end

#resize_to_fill!(ncols, nrows = nil, gravity = CenterGravity) ⇒ Object Also known as: crop_resized!



977
978
979
980
981
982
983
984
985
# File 'lib/RMagick.rb', line 977

def resize_to_fill!(ncols, nrows=nil, gravity=CenterGravity)
    nrows ||= ncols
    if ncols != columns || nrows != rows
        scale = [ncols/columns.to_f, nrows/rows.to_f].max
        resize!(scale*columns+0.5, scale*rows+0.5)
    end
    crop!(gravity, ncols, nrows, true) if ncols != columns || nrows != rows
    self
end

#resize_to_fit(cols, rows = nil) ⇒ Object

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



993
994
995
996
997
998
# File 'lib/RMagick.rb', line 993

def resize_to_fit(cols, rows=nil)
    rows ||= cols
    change_geometry(Geometry.new(cols, rows)) do |ncols, nrows|
        resize(ncols, nrows)
    end
end

#resize_to_fit!(cols, rows = nil) ⇒ Object



1000
1001
1002
1003
1004
1005
# File 'lib/RMagick.rb', line 1000

def resize_to_fit!(cols, rows=nil)
    rows ||= cols
    change_geometry(Geometry.new(cols, rows)) do |ncols, nrows|
        resize!(ncols, nrows)
    end
end

#rollObject

#rotateObject

#rotate!Object

#sampleObject

#sample!Object

#scaleObject

#scale!Object

#segmentObject

#separateObject

#sepiatoneObject

#set_channel_depthObject

#shadeObject

#shadowObject

#sharpenObject

#sharpen_channelObject

#shaveObject

#shave!Object

#shearObject

#sigmoidal_contrast_channelObject

#signatureObject

#sketchObject

#solarizeObject

#sparse_colorObject

#spliceObject

#spreadObject

#steganoObject

#stereoObject

#store_pixelsObject

#strip!Object

#swirlObject

#sync_profilesObject

#texture_fill_to_border(x, y, texture) ⇒ Object

Replace neighboring pixels to border color with texture pixels



1014
1015
1016
# File 'lib/RMagick.rb', line 1014

def texture_fill_to_border(x, y, texture)
    texture_flood_fill(border_color, texture, x, y, FillToBorderMethod)
end

#texture_flood_fillObject

#texture_floodfill(x, y, texture) ⇒ Object

Replace matching neighboring pixels with texture pixels



1008
1009
1010
1011
# File 'lib/RMagick.rb', line 1008

def texture_floodfill(x, y, texture)
    target = pixel_color(x, y)
    texture_flood_fill(target, texture, x, y, FloodfillMethod)
end

#thresholdObject

#thumbnailObject

#thumbnail!Object

#tintObject

#to_blobObject

#to_colorObject

#transparentObject

#transparent_chromaObject

#transposeObject

#transpose!Object

#transverseObject

#transverse!Object

#trimObject

#trim!Object

#undefineObject

#unique_colorsObject

#unsharp_maskObject

#unsharp_mask_channelObject

#view(x, y, width, height) ⇒ Object

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



1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
# File 'lib/RMagick.rb', line 1020

def view(x, y, width, height)
    view = View.new(self, x, y, width, height)

    if block_given?
        begin
            yield(view)
        ensure
            view.sync
        end
        return nil
    else
        return view
    end
end

#vignetteObject

#watermarkObject

#waveObject

#wet_floorObject

#white_thresholdObject

#writeObject