Class Magick::ImageList
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/container.rb ObjectData Application Pre_ObjectData_Descriptor Envelope Post_ObjectData_Descriptor IPTC Magick dot/m_14_0.png

Methods

*   <<   <=>   []   []=   __map__   __map__!   clear   clone   collect   collect!   compact   compact!   concat   copy   cur_image   delay=   delete   delete_at   delete_if   dup   eql?   fill   find_all   from_blob   get_current   indexes   indices   insert   inspect   is_an_image   is_an_image_array   iterations=   last   map!   marshal_dump   marshal_load   method_missing   new   new_image   nitems   partition   ping   pop   push   read   reject   reject!   replace   respond_to?   reverse   reverse!   reverse_each   scene=   select   set_current   shift   slice   slice!   ticks_per_second=   to_a   uniq   uniq!   unshift   values_at  

Included Modules

Comparable Enumerable

External Aliases

length -> size
remap -> affinity
  ImageMagic used affinity in 6.4.3, switch to remap in 6.4.4.
respond_to? -> __respond_to__?
  Ensure respond_to? answers correctly when we are delegating to Image

Attributes

scene  [R] 

Public Class methods

Initialize new instances

[Source]

      # File lib/RMagick.rb, line 1634
1634:     def initialize(*filenames, &block)
1635:         @images = []
1636:         @scene = nil
1637:         filenames.each { |f|
1638:             Magick::Image.read(f, &block).each { |n| @images << n }
1639:             }
1640:         if length > 0
1641:             @scene = length - 1     # last image in array
1642:         end
1643:         self
1644:     end

Public Instance methods

[Source]

      # File lib/RMagick.rb, line 1392
1392:     def *(n)
1393:         unless n.kind_of? Integer
1394:             Kernel.raise ArgumentError, "Integer required (#{n.class} given)"
1395:         end
1396:         current = get_current()
1397:         ilist = self.class.new
1398:         (@images * n).each {|image| ilist << image}
1399:         ilist.set_current current
1400:         return ilist
1401:     end

[Source]

      # File lib/RMagick.rb, line 1403
1403:     def <<(obj)
1404:         is_an_image obj
1405:         @images << obj
1406:         @scene = @images.length - 1
1407:         self
1408:     end

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

[Source]

      # File lib/RMagick.rb, line 1415
1415:     def <=>(other)
1416:         unless other.kind_of? self.class
1417:            Kernel.raise TypeError, "#{self.class} required (#{other.class} given)"
1418:         end
1419:         size = [self.length, other.length].min
1420:         size.times do |x|
1421:             r = self[x] <=> other[x]
1422:             return r unless r == 0
1423:         end
1424:         if @scene.nil? && other.scene.nil?
1425:             return 0
1426:         elsif @scene.nil? && ! other.scene.nil?
1427:             Kernel.raise TypeError, "cannot convert nil into #{other.scene.class}"
1428:         elsif ! @scene.nil? && other.scene.nil?
1429:             Kernel.raise TypeError, "cannot convert nil into #{self.scene.class}"
1430:         end
1431:         r = self.scene <=> other.scene
1432:         return r unless r == 0
1433:         return self.length <=> other.length
1434:     end

[Source]

      # File lib/RMagick.rb, line 1436
1436:     def [](*args)
1437:         a = @images[*args]
1438:         if a.respond_to?(:each) then
1439:             ilist = self.class.new
1440:             a.each {|image| ilist << image}
1441:             a = ilist
1442:         end
1443:         return a
1444:     end

[Source]

      # File lib/RMagick.rb, line 1446
1446:     def []=(*args)
1447:         obj = @images.[]=(*args)
1448:         if obj && obj.respond_to?(:each) then
1449:             is_an_image_array(obj)
1450:             set_current obj.last.__id__
1451:         elsif obj
1452:             is_an_image(obj)
1453:             set_current obj.__id__
1454:         else
1455:             set_current nil
1456:         end
1457:         return obj
1458:     end
__map__(&block)

Alias for collect

__map__!(&block)

Alias for collect!

[Source]

      # File lib/RMagick.rb, line 1478
1478:     def clear
1479:         @scene = nil
1480:         @images.clear
1481:     end

[Source]

      # File lib/RMagick.rb, line 1483
1483:     def clone
1484:         ditto = dup
1485:         ditto.freeze if frozen?
1486:         return ditto
1487:     end

override Enumerable#collect

[Source]

      # File lib/RMagick.rb, line 1490
1490:     def collect(&block)
1491:         current = get_current()
1492:         a = @images.collect(&block)
1493:         ilist = self.class.new
1494:         a.each {|image| ilist << image}
1495:         ilist.set_current current
1496:         return ilist
1497:     end

[Source]

      # File lib/RMagick.rb, line 1499
1499:     def collect!(&block)
1500:         @images.collect!(&block)
1501:         is_an_image_array @images
1502:         self
1503:     end

[Source]

      # File lib/RMagick.rb, line 1530
1530:     def compact
1531:         current = get_current()
1532:         ilist = self.class.new
1533:         a = @images.compact
1534:         a.each {|image| ilist << image}
1535:         ilist.set_current current
1536:         return ilist
1537:     end

[Source]

      # File lib/RMagick.rb, line 1539
1539:     def compact!
1540:         current = get_current()
1541:         a = @images.compact!    # returns nil if no changes were made
1542:         set_current current
1543:         return a.nil? ? nil : self
1544:     end

[Source]

      # File lib/RMagick.rb, line 1546
1546:     def concat(other)
1547:         is_an_image_array other
1548:         other.each {|image| @images << image}
1549:         @scene = length-1
1550:         return self
1551:     end

Make a deep copy

[Source]

      # File lib/RMagick.rb, line 1506
1506:     def copy
1507:         ditto = self.class.new
1508:         @images.each { |f| ditto << f.copy }
1509:         ditto.scene = @scene
1510:         ditto.taint if tainted?
1511:         return ditto
1512:     end

Return the current image

[Source]

      # File lib/RMagick.rb, line 1515
1515:     def cur_image
1516:         if ! @scene
1517:             Kernel.raise IndexError, "no images in this list"
1518:         end
1519:         @images[@scene]
1520:     end

Set same delay for all images

[Source]

      # File lib/RMagick.rb, line 1554
1554:     def delay=(d)
1555:         if Integer(d) < 0
1556:             raise ArgumentError, "delay must be greater than or equal to 0"
1557:         end
1558:         @images.each { |f| f.delay = Integer(d) }
1559:     end

[Source]

      # File lib/RMagick.rb, line 1561
1561:     def delete(obj, &block)
1562:         is_an_image obj
1563:         current = get_current()
1564:         a = @images.delete(obj, &block)
1565:         set_current current
1566:         return a
1567:     end

[Source]

      # File lib/RMagick.rb, line 1569
1569:     def delete_at(ndx)
1570:         current = get_current()
1571:         a = @images.delete_at(ndx)
1572:         set_current current
1573:         return a
1574:     end

[Source]

      # File lib/RMagick.rb, line 1576
1576:     def delete_if(&block)
1577:         current = get_current()
1578:         @images.delete_if(&block)
1579:         set_current current
1580:         self
1581:     end

[Source]

      # File lib/RMagick.rb, line 1583
1583:     def dup
1584:         ditto = self.class.new
1585:         @images.each {|img| ditto << img}
1586:         ditto.scene = @scene
1587:         ditto.taint if tainted?
1588:         return ditto
1589:     end

[Source]

      # File lib/RMagick.rb, line 1591
1591:     def eql?(other)
1592:       is_an_image_array other
1593:       eql = other.eql?(@images)
1594:       begin # "other" is another ImageList
1595:         eql &&= @scene == other.scene
1596:       rescue NoMethodError
1597:         # "other" is a plain Array
1598:       end
1599:       return eql
1600:     end

[Source]

      # File lib/RMagick.rb, line 1602
1602:     def fill(*args, &block)
1603:         is_an_image args[0] unless block_given?
1604:         current = get_current()
1605:         @images.fill(*args, &block)
1606:         is_an_image_array self
1607:         set_current current
1608:         self
1609:     end

Override Enumerable‘s find_all

[Source]

      # File lib/RMagick.rb, line 1612
1612:     def find_all(&block)
1613:         current = get_current()
1614:         a = @images.find_all(&block)
1615:         ilist = self.class.new
1616:         a.each {|image| ilist << image}
1617:         ilist.set_current current
1618:         return ilist
1619:     end

[Source]

      # File lib/RMagick.rb, line 1622
1622:     def from_blob(*blobs, &block)
1623:         if (blobs.length == 0)
1624:             Kernel.raise ArgumentError, "no blobs given"
1625:         end
1626:         blobs.each { |b|
1627:             Magick::Image.from_blob(b, &block).each { |n| @images << n  }
1628:             }
1629:         @scene = length - 1
1630:         self
1631:     end
indexes(*args)

Alias for values_at

indices(*args)

Alias for values_at

[Source]

      # File lib/RMagick.rb, line 1646
1646:     def insert(index, *args)
1647:         args.each {|image| is_an_image image}
1648:         current = get_current()
1649:         @images.insert(index, *args)
1650:         set_current current
1651:         return self
1652:     end

Call inspect for all the images

[Source]

      # File lib/RMagick.rb, line 1655
1655:     def inspect
1656:         img = []
1657:         @images.each {|image| img << image.inspect }
1658:         img = "[" + img.join(",\n") + "]\nscene=#{@scene}"
1659:     end

Set the number of iterations of an animated GIF

[Source]

      # File lib/RMagick.rb, line 1662
1662:     def iterations=(n)
1663:         n = Integer(n)
1664:         if n < 0 || n > 65535
1665:             Kernel.raise ArgumentError, "iterations must be between 0 and 65535"
1666:         end
1667:         @images.each {|f| f.iterations=n}
1668:         self
1669:     end

[Source]

      # File lib/RMagick.rb, line 1671
1671:     def last(*args)
1672:         if args.length == 0
1673:           a = @images.last
1674:         else
1675:           a = @images.last(*args)
1676:           ilist = self.class.new
1677:           a.each {|img| ilist << img}
1678:           @scene = a.length - 1
1679:           a = ilist
1680:         end
1681:         return a
1682:     end
map!(&block)

Alias for collect!

Custom marshal/unmarshal for Ruby 1.8.

[Source]

      # File lib/RMagick.rb, line 1685
1685:     def marshal_dump()
1686:        ary = [@scene]
1687:        @images.each {|i| ary << Marshal.dump(i)}
1688:        ary
1689:     end

[Source]

      # File lib/RMagick.rb, line 1691
1691:     def marshal_load(ary)
1692:        @scene = ary.shift
1693:        @images = []
1694:        ary.each {|a| @images << Marshal.load(a)}
1695:     end

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.

[Source]

      # File lib/RMagick.rb, line 1701
1701:     def method_missing(methID, *args, &block)
1702:         begin
1703:             if @scene
1704:                 @images[@scene].send(methID, *args, &block)
1705:             else
1706:                 super
1707:             end
1708:         rescue NoMethodError
1709:           Kernel.raise NoMethodError, "undefined method `#{methID.id2name}' for #{self.class}"
1710:         rescue Exception
1711:             $@.delete_if { |s| /:in `send'$/.match(s) || /:in `method_missing'$/.match(s) }
1712:             Kernel.raise
1713:         end
1714:     end

Create a new image and add it to the end

[Source]

      # File lib/RMagick.rb, line 1717
1717:     def new_image(cols, rows, *fill, &info_blk)
1718:         self << Magick::Image.new(cols, rows, *fill, &info_blk)
1719:     end

[Source]

      # File lib/RMagick.rb, line 1473
1473:        def nitems()
1474:           @images.nitems()
1475:        end

[Source]

      # File lib/RMagick.rb, line 1721
1721:     def partition(&block)
1722:       a = @images.partition(&block)
1723:       t = self.class.new
1724:       a[0].each { |img| t << img}
1725:       t.set_current nil
1726:       f = self.class.new
1727:       a[1].each { |img| f << img}
1728:       f.set_current nil
1729:       [t, f]
1730:     end

Ping files and concatenate the new images

[Source]

      # File lib/RMagick.rb, line 1733
1733:     def ping(*files, &block)
1734:         if (files.length == 0)
1735:             Kernel.raise ArgumentError, "no files given"
1736:         end
1737:         files.each { |f|
1738:             Magick::Image.ping(f, &block).each { |n| @images << n }
1739:             }
1740:         @scene = length - 1
1741:         self
1742:     end

[Source]

      # File lib/RMagick.rb, line 1744
1744:     def pop
1745:         current = get_current()
1746:         a = @images.pop       # can return nil
1747:         set_current current
1748:         return a
1749:     end

[Source]

      # File lib/RMagick.rb, line 1751
1751:     def push(*objs)
1752:         objs.each do |image|
1753:             is_an_image image
1754:             @images << image
1755:         end
1756:         @scene = length - 1
1757:         self
1758:     end

Read files and concatenate the new images

[Source]

      # File lib/RMagick.rb, line 1761
1761:     def read(*files, &block)
1762:         if (files.length == 0)
1763:             Kernel.raise ArgumentError, "no files given"
1764:         end
1765:         files.each { |f|
1766:             Magick::Image.read(f, &block).each { |n| @images << n }
1767:             }
1768:         @scene = length - 1
1769:         self
1770:     end

override Enumerable‘s reject

[Source]

      # File lib/RMagick.rb, line 1773
1773:     def reject(&block)
1774:         current = get_current()
1775:         ilist = self.class.new
1776:         a = @images.reject(&block)
1777:         a.each {|image| ilist << image}
1778:         ilist.set_current current
1779:         return ilist
1780:     end

[Source]

      # File lib/RMagick.rb, line 1782
1782:     def reject!(&block)
1783:         current = get_current()
1784:         a = @images.reject!(&block)
1785:         @images = a if !a.nil?
1786:         set_current current
1787:         return a.nil? ? nil : self
1788:     end

[Source]

      # File lib/RMagick.rb, line 1790
1790:     def replace(other)
1791:         is_an_image_array other
1792:         current = get_current()
1793:         @images.clear
1794:         other.each {|image| @images << image}
1795:         @scene = self.length == 0 ? nil : 0
1796:         set_current current
1797:         self
1798:     end

[Source]

      # File lib/RMagick.rb, line 1802
1802:     def respond_to?(methID, priv=false)
1803:         return true if __respond_to__?(methID, priv)
1804:         if @scene
1805:             @images[@scene].respond_to?(methID, priv)
1806:         else
1807:             super
1808:         end
1809:     end

[Source]

      # File lib/RMagick.rb, line 1811
1811:     def reverse
1812:         current = get_current()
1813:         a = self.class.new
1814:         @images.reverse_each {|image| a << image}
1815:         a.set_current current
1816:         return a
1817:     end

[Source]

      # File lib/RMagick.rb, line 1819
1819:     def reverse!
1820:         current = get_current()
1821:         @images.reverse!
1822:         set_current current
1823:         self
1824:     end

[Source]

      # File lib/RMagick.rb, line 1826
1826:     def reverse_each
1827:         @images.reverse_each {|image| yield(image)}
1828:         self
1829:     end

Allow scene to be set to nil

[Source]

      # File lib/RMagick.rb, line 1352
1352:     def scene=(n)
1353:         if n.nil?
1354:             Kernel.raise IndexError, "scene number out of bounds" unless @images.length == 0
1355:             @scene = nil
1356:             return @scene
1357:         elsif @images.length == 0
1358:             Kernel.raise IndexError, "scene number out of bounds"
1359:         end
1360: 
1361:         n = Integer(n)
1362:         if n < 0 || n > length - 1
1363:             Kernel.raise IndexError, "scene number out of bounds"
1364:         end
1365:         @scene = n
1366:         return @scene
1367:     end
select(&block)

Alias for find_all

[Source]

      # File lib/RMagick.rb, line 1831
1831:     def shift
1832:         current = get_current()
1833:         a = @images.shift
1834:         set_current current
1835:         return a
1836:     end

[Source]

      # File lib/RMagick.rb, line 1838
1838:     def slice(*args)
1839:         current = get_current()
1840:         slice = @images.slice(*args)
1841:         if slice
1842:             ilist = self.class.new
1843:             if slice.respond_to?(:each) then
1844:                 slice.each {|image| ilist << image}
1845:             else
1846:                 ilist << slice
1847:             end
1848:         else
1849:             ilist = nil
1850:         end
1851:         return ilist
1852:     end

[Source]

      # File lib/RMagick.rb, line 1854
1854:     def slice!(*args)
1855:         current = get_current()
1856:         a = @images.slice!(*args)
1857:         set_current current
1858:         return a
1859:     end

[Source]

      # File lib/RMagick.rb, line 1861
1861:     def ticks_per_second=(t)
1862:         if Integer(t) < 0
1863:             Kernel.raise ArgumentError, "ticks_per_second must be greater than or equal to 0"
1864:         end
1865:         @images.each { |f| f.ticks_per_second = Integer(t) }
1866:     end

[Source]

      # File lib/RMagick.rb, line 1868
1868:     def to_a
1869:         a = Array.new
1870:         @images.each {|image| a << image}
1871:         return a
1872:     end

[Source]

      # File lib/RMagick.rb, line 1874
1874:     def uniq
1875:         current = get_current()
1876:         a = self.class.new
1877:         @images.uniq.each {|image| a << image}
1878:         a.set_current current
1879:         return a
1880:     end

[Source]

      # File lib/RMagick.rb, line 1882
1882:     def uniq!(*args)
1883:         current = get_current()
1884:         a = @images.uniq!
1885:         set_current current
1886:         return a.nil? ? nil : self
1887:     end

@scene -> new object

[Source]

      # File lib/RMagick.rb, line 1890
1890:     def unshift(obj)
1891:         is_an_image obj
1892:         @images.unshift(obj)
1893:         @scene = 0
1894:         self
1895:     end

[Source]

      # File lib/RMagick.rb, line 1897
1897:     def values_at(*args)
1898:         a = @images.values_at(*args)
1899:         a = self.class.new
1900:         @images.values_at(*args).each {|image| a << image}
1901:         a.scene = a.length - 1
1902:         return a
1903:     end

Protected Instance methods

[Source]

      # File lib/RMagick.rb, line 1309
1309:     def is_an_image(obj)
1310:         unless obj.kind_of? Magick::Image
1311:             Kernel.raise ArgumentError, "Magick::Image required (#{obj.class} given)"
1312:         end
1313:         true
1314:     end

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

[Source]

      # File lib/RMagick.rb, line 1317
1317:     def is_an_image_array(ary)
1318:         unless ary.respond_to? :each
1319:             Kernel.raise ArgumentError, "Magick::ImageList or array of Magick::Images required (#{ary.class} given)"
1320:         end
1321:         ary.each { |obj| is_an_image obj }
1322:         true
1323:     end

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

[Source]

      # File lib/RMagick.rb, line 1327
1327:     def set_current(current)
1328:         if length() == 0
1329:             self.scene = nil
1330:             return
1331:         # Don't bother looking for current image
1332:         elsif scene() == nil || scene() >= length()
1333:             self.scene = length() - 1
1334:             return
1335:         elsif current != nil
1336:             # Find last instance of "current" in the list.
1337:             # If "current" isn't in the list, set current to last image.
1338:             self.scene = length() - 1
1339:             each_with_index do |f,i|
1340:                 if f.__id__ == current
1341:                     self.scene = i
1342:                 end
1343:             end
1344:             return
1345:         end
1346:         self.scene = length() - 1
1347:     end

Private Instance methods

[Source]

      # File lib/RMagick.rb, line 1303
1303:     def get_current()
1304:         return @images[@scene].__id__ rescue nil
1305:     end

[Validate]