Initialize new instances
# File lib/RMagick.rb, line 1631 1631: def initialize(*filenames, &block) 1632: @images = [] 1633: @scene = nil 1634: filenames.each { |f| 1635: Magick::Image.read(f, &block).each { |n| @images << n } 1636: } 1637: if length > 0 1638: @scene = length - 1 # last image in array 1639: end 1640: self 1641: end
# File lib/RMagick.rb, line 1390 1390: def *(n) 1391: unless n.kind_of? Integer 1392: Kernel.raise ArgumentError, "Integer required (#{n.class} given)" 1393: end 1394: current = get_current() 1395: ilist = self.class.new 1396: (@images * n).each {|image| ilist << image} 1397: ilist.set_current current 1398: return ilist 1399: end
# File lib/RMagick.rb, line 1401 1401: def <<(obj) 1402: is_an_image obj 1403: @images << obj 1404: @scene = @images.length - 1 1405: self 1406: 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
# File lib/RMagick.rb, line 1413 1413: def <=>(other) 1414: unless other.kind_of? self.class 1415: Kernel.raise TypeError, "#{self.class} required (#{other.class} given)" 1416: end 1417: size = [self.length, other.length].min 1418: size.times do |x| 1419: r = self[x] <=> other[x] 1420: return r unless r == 0 1421: end 1422: if @scene.nil? && other.scene.nil? 1423: return 0 1424: elsif @scene.nil? && ! other.scene.nil? 1425: Kernel.raise TypeError, "cannot convert nil into #{other.scene.class}" 1426: elsif ! @scene.nil? && other.scene.nil? 1427: Kernel.raise TypeError, "cannot convert nil into #{self.scene.class}" 1428: end 1429: r = self.scene <=> other.scene 1430: return r unless r == 0 1431: return self.length <=> other.length 1432: end
# File lib/RMagick.rb, line 1434 1434: def [](*args) 1435: a = @images[*args] 1436: if a.respond_to?(:each) then 1437: ilist = self.class.new 1438: a.each {|image| ilist << image} 1439: a = ilist 1440: end 1441: return a 1442: end
# File lib/RMagick.rb, line 1444 1444: def []=(*args) 1445: obj = @images.[]=(*args) 1446: if obj && obj.respond_to?(:each) then 1447: is_an_image_array(obj) 1448: set_current obj.last.__id__ 1449: elsif obj 1450: is_an_image(obj) 1451: set_current obj.__id__ 1452: else 1453: set_current nil 1454: end 1455: return obj 1456: end
ImageList#map took over the “map” name. Use alternatives.
Ensure respond_to? answers correctly when we are delegating to Image
# File lib/RMagick.rb, line 1475 1475: def clear 1476: @scene = nil 1477: @images.clear 1478: end
# File lib/RMagick.rb, line 1480 1480: def clone 1481: ditto = dup 1482: ditto.freeze if frozen? 1483: return ditto 1484: end
override Enumerable#collect
# File lib/RMagick.rb, line 1487 1487: def collect(&block) 1488: current = get_current() 1489: a = @images.collect(&block) 1490: ilist = self.class.new 1491: a.each {|image| ilist << image} 1492: ilist.set_current current 1493: return ilist 1494: end
# File lib/RMagick.rb, line 1496 1496: def collect!(&block) 1497: @images.collect!(&block) 1498: is_an_image_array @images 1499: self 1500: end
# File lib/RMagick.rb, line 1527 1527: def compact 1528: current = get_current() 1529: ilist = self.class.new 1530: a = @images.compact 1531: a.each {|image| ilist << image} 1532: ilist.set_current current 1533: return ilist 1534: end
# File lib/RMagick.rb, line 1536 1536: def compact! 1537: current = get_current() 1538: a = @images.compact! # returns nil if no changes were made 1539: set_current current 1540: return a.nil? ? nil : self 1541: end
# File lib/RMagick.rb, line 1543 1543: def concat(other) 1544: is_an_image_array other 1545: other.each {|image| @images << image} 1546: @scene = length-1 1547: return self 1548: end
Make a deep copy
# File lib/RMagick.rb, line 1503 1503: def copy 1504: ditto = self.class.new 1505: @images.each { |f| ditto << f.copy } 1506: ditto.scene = @scene 1507: ditto.taint if tainted? 1508: return ditto 1509: end
Return the current image
# File lib/RMagick.rb, line 1512 1512: def cur_image 1513: if ! @scene 1514: Kernel.raise IndexError, "no images in this list" 1515: end 1516: @images[@scene] 1517: end
Set same delay for all images
# File lib/RMagick.rb, line 1551 1551: def delay=(d) 1552: if Integer(d) < 0 1553: raise ArgumentError, "delay must be greater than or equal to 0" 1554: end 1555: @images.each { |f| f.delay = Integer(d) } 1556: end
# File lib/RMagick.rb, line 1558 1558: def delete(obj, &block) 1559: is_an_image obj 1560: current = get_current() 1561: a = @images.delete(obj, &block) 1562: set_current current 1563: return a 1564: end
# File lib/RMagick.rb, line 1566 1566: def delete_at(ndx) 1567: current = get_current() 1568: a = @images.delete_at(ndx) 1569: set_current current 1570: return a 1571: end
# File lib/RMagick.rb, line 1573 1573: def delete_if(&block) 1574: current = get_current() 1575: @images.delete_if(&block) 1576: set_current current 1577: self 1578: end
# File lib/RMagick.rb, line 1580 1580: def dup 1581: ditto = self.class.new 1582: @images.each {|img| ditto << img} 1583: ditto.scene = @scene 1584: ditto.taint if tainted? 1585: return ditto 1586: end
# File lib/RMagick.rb, line 1588 1588: def eql?(other) 1589: is_an_image_array other 1590: eql = other.eql?(@images) 1591: begin # "other" is another ImageList 1592: eql &&= @scene == other.scene 1593: rescue NoMethodError 1594: # "other" is a plain Array 1595: end 1596: return eql 1597: end
# File lib/RMagick.rb, line 1599 1599: def fill(*args, &block) 1600: is_an_image args[0] unless block_given? 1601: current = get_current() 1602: @images.fill(*args, &block) 1603: is_an_image_array self 1604: set_current current 1605: self 1606: end
Override Enumerable’s find_all
# File lib/RMagick.rb, line 1609 1609: def find_all(&block) 1610: current = get_current() 1611: a = @images.find_all(&block) 1612: ilist = self.class.new 1613: a.each {|image| ilist << image} 1614: ilist.set_current current 1615: return ilist 1616: end
# File lib/RMagick.rb, line 1619 1619: def from_blob(*blobs, &block) 1620: if (blobs.length == 0) 1621: Kernel.raise ArgumentError, "no blobs given" 1622: end 1623: blobs.each { |b| 1624: Magick::Image.from_blob(b, &block).each { |n| @images << n } 1625: } 1626: @scene = length - 1 1627: self 1628: end
# File lib/RMagick.rb, line 1643 1643: def insert(index, *args) 1644: args.each {|image| is_an_image image} 1645: current = get_current() 1646: @images.insert(index, *args) 1647: set_current current 1648: return self 1649: end
Call inspect for all the images
# File lib/RMagick.rb, line 1652 1652: def inspect 1653: img = [] 1654: @images.each {|image| img << image.inspect } 1655: img = "[" + img.join(",\n") + "]\nscene=#{@scene}" 1656: end
Set the number of iterations of an animated GIF
# File lib/RMagick.rb, line 1659 1659: def iterations=(n) 1660: n = Integer(n) 1661: if n < 0 || n > 65535 1662: Kernel.raise ArgumentError, "iterations must be between 0 and 65535" 1663: end 1664: @images.each {|f| f.iterations=n} 1665: self 1666: end
# File lib/RMagick.rb, line 1668 1668: def last(*args) 1669: if args.length == 0 1670: a = @images.last 1671: else 1672: a = @images.last(*args) 1673: ilist = self.class.new 1674: a.each {|img| ilist << img} 1675: @scene = a.length - 1 1676: a = ilist 1677: end 1678: return a 1679: end
Custom marshal/unmarshal for Ruby 1.8.
# File lib/RMagick.rb, line 1682 1682: def marshal_dump() 1683: ary = [@scene] 1684: @images.each {|i| ary << Marshal.dump(i)} 1685: ary 1686: end
# File lib/RMagick.rb, line 1688 1688: def marshal_load(ary) 1689: @scene = ary.shift 1690: @images = [] 1691: ary.each {|a| @images << Marshal.load(a)} 1692: 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.
# File lib/RMagick.rb, line 1698 1698: def method_missing(methID, *args, &block) 1699: begin 1700: if @scene 1701: @images[@scene].send(methID, *args, &block) 1702: else 1703: super 1704: end 1705: rescue NoMethodError 1706: Kernel.raise NoMethodError, "undefined method `#{methID.id2name}' for #{self.class}" 1707: rescue Exception 1708: $@.delete_if { |s| /:in `send'$/.match(s) || /:in `method_missing'$/.match(s) } 1709: Kernel.raise 1710: end 1711: end
Create a new image and add it to the end
# File lib/RMagick.rb, line 1714 1714: def new_image(cols, rows, *fill, &info_blk) 1715: self << Magick::Image.new(cols, rows, *fill, &info_blk) 1716: end
# File lib/RMagick.rb, line 1470 1470: def nitems() 1471: @images.nitems() 1472: end
# File lib/RMagick.rb, line 1718 1718: def partition(&block) 1719: a = @images.partition(&block) 1720: t = self.class.new 1721: a[0].each { |img| t << img} 1722: t.set_current nil 1723: f = self.class.new 1724: a[1].each { |img| f << img} 1725: f.set_current nil 1726: [t, f] 1727: end
Ping files and concatenate the new images
# File lib/RMagick.rb, line 1730 1730: def ping(*files, &block) 1731: if (files.length == 0) 1732: Kernel.raise ArgumentError, "no files given" 1733: end 1734: files.each { |f| 1735: Magick::Image.ping(f, &block).each { |n| @images << n } 1736: } 1737: @scene = length - 1 1738: self 1739: end
# File lib/RMagick.rb, line 1741 1741: def pop 1742: current = get_current() 1743: a = @images.pop # can return nil 1744: set_current current 1745: return a 1746: end
# File lib/RMagick.rb, line 1748 1748: def push(*objs) 1749: objs.each do |image| 1750: is_an_image image 1751: @images << image 1752: end 1753: @scene = length - 1 1754: self 1755: end
Read files and concatenate the new images
# File lib/RMagick.rb, line 1758 1758: def read(*files, &block) 1759: if (files.length == 0) 1760: Kernel.raise ArgumentError, "no files given" 1761: end 1762: files.each { |f| 1763: Magick::Image.read(f, &block).each { |n| @images << n } 1764: } 1765: @scene = length - 1 1766: self 1767: end
override Enumerable’s reject
# File lib/RMagick.rb, line 1770 1770: def reject(&block) 1771: current = get_current() 1772: ilist = self.class.new 1773: a = @images.reject(&block) 1774: a.each {|image| ilist << image} 1775: ilist.set_current current 1776: return ilist 1777: end
# File lib/RMagick.rb, line 1779 1779: def reject!(&block) 1780: current = get_current() 1781: a = @images.reject!(&block) 1782: @images = a if !a.nil? 1783: set_current current 1784: return a.nil? ? nil : self 1785: end
# File lib/RMagick.rb, line 1787 1787: def replace(other) 1788: is_an_image_array other 1789: current = get_current() 1790: @images.clear 1791: other.each {|image| @images << image} 1792: @scene = self.length == 0 ? nil : 0 1793: set_current current 1794: self 1795: end
# File lib/RMagick.rb, line 1799 1799: def respond_to?(methID, priv=false) 1800: return true if __respond_to__?(methID, priv) 1801: if @scene 1802: @images[@scene].respond_to?(methID, priv) 1803: else 1804: super 1805: end 1806: end
# File lib/RMagick.rb, line 1808 1808: def reverse 1809: current = get_current() 1810: a = self.class.new 1811: @images.reverse_each {|image| a << image} 1812: a.set_current current 1813: return a 1814: end
# File lib/RMagick.rb, line 1816 1816: def reverse! 1817: current = get_current() 1818: @images.reverse! 1819: set_current current 1820: self 1821: end
# File lib/RMagick.rb, line 1823 1823: def reverse_each 1824: @images.reverse_each {|image| yield(image)} 1825: self 1826: end
Allow scene to be set to nil
# File lib/RMagick.rb, line 1351 1351: def scene=(n) 1352: if n.nil? 1353: Kernel.raise IndexError, "scene number out of bounds" unless @images.length == 0 1354: @scene = nil 1355: return @scene 1356: elsif @images.length == 0 1357: Kernel.raise IndexError, "scene number out of bounds" 1358: end 1359: 1360: n = Integer(n) 1361: if n < 0 || n > length - 1 1362: Kernel.raise IndexError, "scene number out of bounds" 1363: end 1364: @scene = n 1365: return @scene 1366: end
# File lib/RMagick.rb, line 1828 1828: def shift 1829: current = get_current() 1830: a = @images.shift 1831: set_current current 1832: return a 1833: end
# File lib/RMagick.rb, line 1835 1835: def slice(*args) 1836: current = get_current() 1837: slice = @images.slice(*args) 1838: if slice 1839: ilist = self.class.new 1840: if slice.respond_to?(:each) then 1841: slice.each {|image| ilist << image} 1842: else 1843: ilist << slice 1844: end 1845: else 1846: ilist = nil 1847: end 1848: return ilist 1849: end
# File lib/RMagick.rb, line 1851 1851: def slice!(*args) 1852: current = get_current() 1853: a = @images.slice!(*args) 1854: set_current current 1855: return a 1856: end
# File lib/RMagick.rb, line 1858 1858: def ticks_per_second=(t) 1859: if Integer(t) < 0 1860: Kernel.raise ArgumentError, "ticks_per_second must be greater than or equal to 0" 1861: end 1862: @images.each { |f| f.ticks_per_second = Integer(t) } 1863: end
# File lib/RMagick.rb, line 1865 1865: def to_a 1866: a = Array.new 1867: @images.each {|image| a << image} 1868: return a 1869: end
# File lib/RMagick.rb, line 1871 1871: def uniq 1872: current = get_current() 1873: a = self.class.new 1874: @images.uniq.each {|image| a << image} 1875: a.set_current current 1876: return a 1877: end
# File lib/RMagick.rb, line 1879 1879: def uniq!(*args) 1880: current = get_current() 1881: a = @images.uniq! 1882: set_current current 1883: return a.nil? ? nil : self 1884: end
@scene -> new object
# File lib/RMagick.rb, line 1887 1887: def unshift(obj) 1888: is_an_image obj 1889: @images.unshift(obj) 1890: @scene = 0 1891: self 1892: end
# File lib/RMagick.rb, line 1308 1308: def is_an_image(obj) 1309: unless obj.kind_of? Magick::Image 1310: Kernel.raise ArgumentError, "Magick::Image required (#{obj.class} given)" 1311: end 1312: true 1313: end
Ensure array is always an array of Magick::Image objects
# File lib/RMagick.rb, line 1316 1316: def is_an_image_array(ary) 1317: unless ary.respond_to? :each 1318: Kernel.raise ArgumentError, "Magick::ImageList or array of Magick::Images required (#{ary.class} given)" 1319: end 1320: ary.each { |obj| is_an_image obj } 1321: true 1322: end
Find old current image, update scene number current is the id of the old current image.
# File lib/RMagick.rb, line 1326 1326: def set_current(current) 1327: if length() == 0 1328: self.scene = nil 1329: return 1330: # Don't bother looking for current image 1331: elsif scene() == nil || scene() >= length() 1332: self.scene = length() - 1 1333: return 1334: elsif current != nil 1335: # Find last instance of "current" in the list. 1336: # If "current" isn't in the list, set current to last image. 1337: self.scene = length() - 1 1338: each_with_index do |f,i| 1339: if f.__id__ == current 1340: self.scene = i 1341: end 1342: end 1343: return 1344: end 1345: self.scene = length() - 1 1346: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.