class Magick::ImageList


Attributes

scene[R]

Public Class Methods

new(*filenames, &block) click to toggle source

Initialize new instances

# File lib/rmagick_internal.rb, line 1621
def initialize(*filenames, &block)
    @images = []
    @scene = nil
    filenames.each { |f|
        Magick::Image.read(f, &block).each { |n| @images << n }
        }
    if length > 0
        @scene = length - 1     # last image in array
    end
    self
end

Public Instance Methods

*(n) click to toggle source
# File lib/rmagick_internal.rb, line 1380
def *(n)
    unless n.kind_of? Integer
        Kernel.raise ArgumentError, "Integer required (#{n.class} given)"
    end
    current = get_current()
    ilist = self.class.new
    (@images * n).each {|image| ilist << image}
    ilist.set_current current
    return ilist
end
<<(obj) click to toggle source
# File lib/rmagick_internal.rb, line 1391
def <<(obj)
    is_an_image obj
    @images << obj
    @scene = @images.length - 1
    self
end
<=>(other) click to toggle source

Compare ImageLists Compare each image in turn until the result of a comparison is not 0. If all comparisons return 0, then

return if A.scene != B.scene
return A.length <=> B.length
# File lib/rmagick_internal.rb, line 1403
def <=>(other)
    unless other.kind_of? self.class
       Kernel.raise TypeError, "#{self.class} required (#{other.class} given)"
    end
    size = [self.length, other.length].min
    size.times do |x|
        r = self[x] <=> other[x]
        return r unless r == 0
    end
    if @scene.nil? && other.scene.nil?
        return 0
    elsif @scene.nil? && ! other.scene.nil?
        Kernel.raise TypeError, "cannot convert nil into #{other.scene.class}"
    elsif ! @scene.nil? && other.scene.nil?
        Kernel.raise TypeError, "cannot convert nil into #{self.scene.class}"
    end
    r = self.scene <=> other.scene
    return r unless r == 0
    return self.length <=> other.length
end
[](*args) click to toggle source
# File lib/rmagick_internal.rb, line 1424
def [](*args)
    a = @images[*args]
    if a.respond_to?(:each) then
        ilist = self.class.new
        a.each {|image| ilist << image}
        a = ilist
    end
    return a
end
[]=(*args) click to toggle source
# File lib/rmagick_internal.rb, line 1434
def []=(*args)
    obj = @images.[]=(*args)
    if obj && obj.respond_to?(:each) then
        is_an_image_array(obj)
        set_current obj.last.__id__
    elsif obj
        is_an_image(obj)
        set_current obj.__id__
    else
        set_current nil
    end
    return obj
end
__map__(&block)

ImageList#map took over the “map” name. Use alternatives.

Alias for: collect
__map__!(&block)
Alias for: collect!
__respond_to__?(methID, priv=false)

Ensure respond_to? answers correctly when we are delegating to Image

Alias for: respond_to?
clear() click to toggle source
# File lib/rmagick_internal.rb, line 1465
def clear
    @scene = nil
    @images.clear
end
clone() click to toggle source
# File lib/rmagick_internal.rb, line 1470
def clone
    ditto = dup
    ditto.freeze if frozen?
    return ditto
end
collect(&block) click to toggle source

override Enumerable#collect

# File lib/rmagick_internal.rb, line 1477
def collect(&block)
    current = get_current()
    a = @images.collect(&block)
    ilist = self.class.new
    a.each {|image| ilist << image}
    ilist.set_current current
    return ilist
end
Also aliased as: __map__
collect!(&block) click to toggle source
# File lib/rmagick_internal.rb, line 1486
def collect!(&block)
    @images.collect!(&block)
    is_an_image_array @images
    self
end
Also aliased as: map!, __map__!
compact() click to toggle source
# File lib/rmagick_internal.rb, line 1517
def compact
    current = get_current()
    ilist = self.class.new
    a = @images.compact
    a.each {|image| ilist << image}
    ilist.set_current current
    return ilist
end
compact!() click to toggle source
# File lib/rmagick_internal.rb, line 1526
def compact!
    current = get_current()
    a = @images.compact!    # returns nil if no changes were made
    set_current current
    return a.nil? ? nil : self
end
concat(other) click to toggle source
# File lib/rmagick_internal.rb, line 1533
def concat(other)
    is_an_image_array other
    other.each {|image| @images << image}
    @scene = length-1
    return self
end
copy() click to toggle source

Make a deep copy

# File lib/rmagick_internal.rb, line 1493
def copy
    ditto = self.class.new
    @images.each { |f| ditto << f.copy }
    ditto.scene = @scene
    ditto.taint if tainted?
    return ditto
end
cur_image() click to toggle source

Return the current image

# File lib/rmagick_internal.rb, line 1502
def cur_image
    if ! @scene
        Kernel.raise IndexError, "no images in this list"
    end
    @images[@scene]
end
delay=(d) click to toggle source

Set same delay for all images

# File lib/rmagick_internal.rb, line 1541
def delay=(d)
    if Integer(d) < 0
        raise ArgumentError, "delay must be greater than or equal to 0"
    end
    @images.each { |f| f.delay = Integer(d) }
end
delete(obj, &block) click to toggle source
# File lib/rmagick_internal.rb, line 1548
def delete(obj, &block)
    is_an_image obj
    current = get_current()
    a = @images.delete(obj, &block)
    set_current current
    return a
end
delete_at(ndx) click to toggle source
# File lib/rmagick_internal.rb, line 1556
def delete_at(ndx)
    current = get_current()
    a = @images.delete_at(ndx)
    set_current current
    return a
end
delete_if(&block) click to toggle source
# File lib/rmagick_internal.rb, line 1563
def delete_if(&block)
    current = get_current()
    @images.delete_if(&block)
    set_current current
    self
end
dup() click to toggle source
# File lib/rmagick_internal.rb, line 1570
def dup
    ditto = self.class.new
    @images.each {|img| ditto << img}
    ditto.scene = @scene
    ditto.taint if tainted?
    return ditto
end
eql?(other) click to toggle source
# File lib/rmagick_internal.rb, line 1578
def eql?(other)
  is_an_image_array other
  eql = other.eql?(@images)
  begin # "other" is another ImageList
    eql &&= @scene == other.scene
  rescue NoMethodError
    # "other" is a plain Array
  end
  return eql
end
fill(*args, &block) click to toggle source
# File lib/rmagick_internal.rb, line 1589
def fill(*args, &block)
    is_an_image args[0] unless block_given?
    current = get_current()
    @images.fill(*args, &block)
    is_an_image_array self
    set_current current
    self
end
find_all(&block) click to toggle source

Override Enumerable's #find_all

# File lib/rmagick_internal.rb, line 1599
def find_all(&block)
    current = get_current()
    a = @images.find_all(&block)
    ilist = self.class.new
    a.each {|image| ilist << image}
    ilist.set_current current
    return ilist
end
Also aliased as: select
from_blob(*blobs, &block) click to toggle source
# File lib/rmagick_internal.rb, line 1609
def from_blob(*blobs, &block)
    if (blobs.length == 0)
        Kernel.raise ArgumentError, "no blobs given"
    end
    blobs.each { |b|
        Magick::Image.from_blob(b, &block).each { |n| @images << n  }
        }
    @scene = length - 1
    self
end
indexes(*args)
Alias for: values_at
indices(*args)
Alias for: values_at
insert(index, *args) click to toggle source
# File lib/rmagick_internal.rb, line 1633
def insert(index, *args)
    args.each {|image| is_an_image image}
    current = get_current()
    @images.insert(index, *args)
    set_current current
    return self
end
inspect() click to toggle source

Call inspect for all the images

# File lib/rmagick_internal.rb, line 1642
def inspect
    img = []
    @images.each {|image| img << image.inspect }
    img = "[" + img.join(",\n") + "]\nscene=#{@scene}"
end
iterations=(n) click to toggle source

Set the number of iterations of an animated GIF

# File lib/rmagick_internal.rb, line 1649
def iterations=(n)
    n = Integer(n)
    if n < 0 || n > 65535
        Kernel.raise ArgumentError, "iterations must be between 0 and 65535"
    end
    @images.each {|f| f.iterations=n}
    self
end
last(*args) click to toggle source
# File lib/rmagick_internal.rb, line 1658
def last(*args)
    if args.length == 0
      a = @images.last
    else
      a = @images.last(*args)
      ilist = self.class.new
      a.each {|img| ilist << img}
      @scene = a.length - 1
      a = ilist
    end
    return a
end
map!(&block)
Alias for: collect!
marshal_dump() click to toggle source

Custom marshal/unmarshal for Ruby 1.8.

# File lib/rmagick_internal.rb, line 1672
def marshal_dump()
   ary = [@scene]
   @images.each {|i| ary << Marshal.dump(i)}
   ary
end
marshal_load(ary) click to toggle source
# File lib/rmagick_internal.rb, line 1678
def marshal_load(ary)
   @scene = ary.shift
   @images = []
   ary.each {|a| @images << Marshal.load(a)}
end
method_missing(methID, *args, &block) click to toggle source

The ImageList class supports the Magick::Image class methods by simply sending the method to the current image. If the method isn't explicitly supported, send it to the current image in the array. If there are no images, send it up the line. Catch a NameError and emit a useful message.

Calls superclass method
# File lib/rmagick_internal.rb, line 1688
def method_missing(methID, *args, &block)
    begin
        if @scene
            @images[@scene].send(methID, *args, &block)
        else
            super
        end
    rescue NoMethodError
      Kernel.raise NoMethodError, "undefined method `#{methID.id2name}' for #{self.class}"
    rescue Exception
        $@.delete_if { |s| /:in `send'$/.match(s) || /:in `method_missing'$/.match(s) }
        Kernel.raise
    end
end
new_image(cols, rows, *fill, &info_blk) click to toggle source

Create a new image and add it to the end

# File lib/rmagick_internal.rb, line 1704
def new_image(cols, rows, *fill, &info_blk)
    self << Magick::Image.new(cols, rows, *fill, &info_blk)
end
nitems() click to toggle source
# File lib/rmagick_internal.rb, line 1460
def nitems()
   @images.nitems()
end
partition(&block) click to toggle source
# File lib/rmagick_internal.rb, line 1708
def partition(&block)
  a = @images.partition(&block)
  t = self.class.new
  a[0].each { |img| t << img}
  t.set_current nil
  f = self.class.new
  a[1].each { |img| f << img}
  f.set_current nil
  [t, f]
end
ping(*files, &block) click to toggle source

Ping files and concatenate the new images

# File lib/rmagick_internal.rb, line 1720
def ping(*files, &block)
    if (files.length == 0)
        Kernel.raise ArgumentError, "no files given"
    end
    files.each { |f|
        Magick::Image.ping(f, &block).each { |n| @images << n }
        }
    @scene = length - 1
    self
end
pop() click to toggle source
# File lib/rmagick_internal.rb, line 1731
def pop
    current = get_current()
    a = @images.pop       # can return nil
    set_current current
    return a
end
push(*objs) click to toggle source
# File lib/rmagick_internal.rb, line 1738
def push(*objs)
    objs.each do |image|
        is_an_image image
        @images << image
    end
    @scene = length - 1
    self
end
read(*files, &block) click to toggle source

Read files and concatenate the new images

# File lib/rmagick_internal.rb, line 1748
def read(*files, &block)
    if (files.length == 0)
        Kernel.raise ArgumentError, "no files given"
    end
    files.each { |f|
        Magick::Image.read(f, &block).each { |n| @images << n }
        }
    @scene = length - 1
    self
end
reject(&block) click to toggle source

override Enumerable's reject

# File lib/rmagick_internal.rb, line 1760
def reject(&block)
    current = get_current()
    ilist = self.class.new
    a = @images.reject(&block)
    a.each {|image| ilist << image}
    ilist.set_current current
    return ilist
end
reject!(&block) click to toggle source
# File lib/rmagick_internal.rb, line 1769
def reject!(&block)
    current = get_current()
    a = @images.reject!(&block)
    @images = a if !a.nil?
    set_current current
    return a.nil? ? nil : self
end
replace(other) click to toggle source
# File lib/rmagick_internal.rb, line 1777
def replace(other)
    is_an_image_array other
    current = get_current()
    @images.clear
    other.each {|image| @images << image}
    @scene = self.length == 0 ? nil : 0
    set_current current
    self
end
respond_to?(methID, priv=false) click to toggle source
Calls superclass method
# File lib/rmagick_internal.rb, line 1789
def respond_to?(methID, priv=false)
    return true if __respond_to__?(methID, priv)
    if @scene
        @images[@scene].respond_to?(methID, priv)
    else
        super
    end
end
Also aliased as: __respond_to__?
reverse() click to toggle source
# File lib/rmagick_internal.rb, line 1798
def reverse
    current = get_current()
    a = self.class.new
    @images.reverse_each {|image| a << image}
    a.set_current current
    return a
end
reverse!() click to toggle source
# File lib/rmagick_internal.rb, line 1806
def reverse!
    current = get_current()
    @images.reverse!
    set_current current
    self
end
reverse_each() { |image| ... } click to toggle source
# File lib/rmagick_internal.rb, line 1813
def reverse_each
    @images.reverse_each {|image| yield(image)}
    self
end
scene=(n) click to toggle source

Allow scene to be set to nil

# File lib/rmagick_internal.rb, line 1341
def scene=(n)
    if n.nil?
        Kernel.raise IndexError, "scene number out of bounds" unless @images.length == 0
        @scene = nil
        return @scene
    elsif @images.length == 0
        Kernel.raise IndexError, "scene number out of bounds"
    end

    n = Integer(n)
    if n < 0 || n > length - 1
        Kernel.raise IndexError, "scene number out of bounds"
    end
    @scene = n
    return @scene
end
select(&block)
Alias for: find_all
shift() click to toggle source
# File lib/rmagick_internal.rb, line 1818
def shift
    current = get_current()
    a = @images.shift
    set_current current
    return a
end
slice(*args) click to toggle source
# File lib/rmagick_internal.rb, line 1825
def slice(*args)
    current = get_current()
    slice = @images.slice(*args)
    if slice
        ilist = self.class.new
        if slice.respond_to?(:each) then
            slice.each {|image| ilist << image}
        else
            ilist << slice
        end
    else
        ilist = nil
    end
    return ilist
end
slice!(*args) click to toggle source
# File lib/rmagick_internal.rb, line 1841
def slice!(*args)
    current = get_current()
    a = @images.slice!(*args)
    set_current current
    return a
end
ticks_per_second=(t) click to toggle source
# File lib/rmagick_internal.rb, line 1848
def ticks_per_second=(t)
    if Integer(t) < 0
        Kernel.raise ArgumentError, "ticks_per_second must be greater than or equal to 0"
    end
    @images.each { |f| f.ticks_per_second = Integer(t) }
end
to_a() click to toggle source
# File lib/rmagick_internal.rb, line 1855
def to_a
    a = Array.new
    @images.each {|image| a << image}
    return a
end
uniq() click to toggle source
# File lib/rmagick_internal.rb, line 1861
def uniq
    current = get_current()
    a = self.class.new
    @images.uniq.each {|image| a << image}
    a.set_current current
    return a
end
uniq!(*args) click to toggle source
# File lib/rmagick_internal.rb, line 1869
def uniq!(*args)
    current = get_current()
    a = @images.uniq!
    set_current current
    return a.nil? ? nil : self
end
unshift(obj) click to toggle source

@scene -> new object

# File lib/rmagick_internal.rb, line 1877
def unshift(obj)
    is_an_image obj
    @images.unshift(obj)
    @scene = 0
    self
end
values_at(*args) click to toggle source
# File lib/rmagick_internal.rb, line 1884
def values_at(*args)
    a = @images.values_at(*args)
    a = self.class.new
    @images.values_at(*args).each {|image| a << image}
    a.scene = a.length - 1
    return a
end
Also aliased as: indexes, indices

Protected Instance Methods

is_an_image(obj) click to toggle source
# File lib/rmagick_internal.rb, line 1298
def is_an_image(obj)
    unless obj.kind_of? Magick::Image
        Kernel.raise ArgumentError, "Magick::Image required (#{obj.class} given)"
    end
    true
end
is_an_image_array(ary) click to toggle source

Ensure array is always an array of Magick::Image objects

# File lib/rmagick_internal.rb, line 1306
def is_an_image_array(ary)
    unless ary.respond_to? :each
        Kernel.raise ArgumentError, "Magick::ImageList or array of Magick::Images required (#{ary.class} given)"
    end
    ary.each { |obj| is_an_image obj }
    true
end
set_current(current) click to toggle source

Find old current image, update scene number current is the id of the old current image.

# File lib/rmagick_internal.rb, line 1316
def set_current(current)
    if length() == 0
        self.scene = nil
        return
    # Don't bother looking for current image
    elsif scene() == nil || scene() >= length()
        self.scene = length() - 1
        return
    elsif current != nil
        # Find last instance of "current" in the list.
        # If "current" isn't in the list, set current to last image.
        self.scene = length() - 1
        each_with_index do |f,i|
            if f.__id__ == current
                self.scene = i
            end
        end
        return
    end
    self.scene = length() - 1
end