Class Magick::ImageList
In: lib/RMagick.rb
Parent: Array
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 Array Geometry HatchFill Draw lib/RMagick.rb lib/rvg/misc.rb Application ObjectData Pre_ObjectData_Descriptor Envelope Post_ObjectData_Descriptor IPTC Magick dot/m_14_0.png

Methods

&   *   +   -   <<   <=>   []   []=   __map__   clear   clone   collect   collect!   compact   compact!   concat   copy   cur_image   delay=   delete   delete_at   delete_if   dup   fill   find_all   from_blob   insert   inspect   is_a_image   is_a_image_array   iterations=   map!   method_missing   new   new_image   ping   pop   push   read   reject   reject!   replace   respond_to?   reverse   reverse!   scene=   select   set_cf   shift   slice   slice!   ticks_per_second=   uniq   uniq!   unshift   |  

Included Modules

Comparable

External Aliases

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 1657
1657:     def initialize(*filenames)
1658:         @scene = nil
1659:         filenames.each { |f|
1660:             Magick::Image.read(f).each { |n| self << n }
1661:             }
1662:         if length > 0
1663:             @scene = length - 1     # last image in array
1664:         end
1665:         self
1666:     end

Public Instance methods

[Source]

      # File lib/RMagick.rb, line 1303
1303:     def &(other)
1304:         is_a_image_array other
1305:         cfid = self[@scene].__id__ rescue nil
1306:         a = self.class.new.replace super
1307:         a.set_cf cfid
1308:         return a
1309:     end

[Source]

      # File lib/RMagick.rb, line 1311
1311:     def *(n)
1312:         unless n.kind_of? Integer
1313:             Kernel.raise ArgumentError, "Integer required (#{n.class} given)"
1314:         end
1315:         cfid = self[@scene].__id__ rescue nil
1316:         a = self.class.new.replace super
1317:         a.set_cf cfid
1318:         return a
1319:     end

[Source]

      # File lib/RMagick.rb, line 1321
1321:     def +(other)
1322:         cfid = self[@scene].__id__ rescue nil
1323:         a = self.class.new.replace super
1324:         a.set_cf cfid
1325:         return a
1326:     end

[Source]

      # File lib/RMagick.rb, line 1328
1328:     def -(other)
1329:         is_a_image_array other
1330:         cfid = self[@scene].__id__ rescue nil
1331:         a = self.class.new.replace super
1332:         a.set_cf cfid
1333:         return a
1334:     end

[Source]

      # File lib/RMagick.rb, line 1336
1336:     def <<(obj)
1337:         is_a_image obj
1338:         a = super
1339:         @scene = length-1
1340:         return a
1341:     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 1578
1578:     def <=>(other)
1579:         unless other.kind_of? self.class
1580:            Kernel.raise TypeError, "#{self.class} required (#{other.class} given)"
1581:         end
1582:         size = [self.length, other.length].min
1583:         size.times do |x|
1584:             r = self[x] <=> other[x]
1585:             return r unless r == 0
1586:         end
1587:         if @scene.nil? && other.scene.nil?
1588:             return 0
1589:         elsif @scene.nil? && ! other.scene.nil?
1590:             Kernel.raise TypeError, "cannot convert nil into #{other.scene.class}"
1591:         elsif ! @scene.nil? && other.scene.nil?
1592:             Kernel.raise TypeError, "cannot convert nil into #{self.scene.class}"
1593:         end
1594:         r = self.scene <=> other.scene
1595:         return r unless r == 0
1596:         return self.length <=> other.length
1597:     end

[Source]

      # File lib/RMagick.rb, line 1272
1272:     def [](*args)
1273:         if (args.length > 1) || args[0].kind_of?(Range)
1274:             self.class.new.replace super
1275:         else
1276:             super
1277:         end
1278:     end

[Source]

      # File lib/RMagick.rb, line 1280
1280:     def []=(*args)
1281:         if args.length == 3             # f[start,length] = [f1,f2...]
1282:             args[2].kind_of?(Magick::Image) || is_a_image_array(args[2])
1283:             super
1284:             args[0] = args[0] + length if (args[0] < 0)
1285:             args[1] = length - args[0] if (args[0] + args[1] > length)
1286:             if args[2].kind_of?(Magick::Image)
1287:                 @scene = args[0]
1288:             else
1289:                 @scene = args[0] + args[2].length - 1
1290:             end
1291:         elsif args[0].kind_of? Range    # f[first..last] = [f1,f2...]
1292:             args[1].kind_of?(Magick::Image) || is_a_image_array(args[1])
1293:             super
1294:             @scene = args[0].end
1295:         else                            # f[index] = f1
1296:             is_a_image args[1]
1297:             super                       # index can be negative
1298:             @scene = args[0] < 0 ? length + args[0] : args[0]
1299:         end
1300:         args.last                       # return value is always assigned value
1301:     end

Enumerable (or Array) has a map method that conflicts with our own map method. RMagick.so has defined a synonym for that map called Array#ary_map. Here, we define Magick::ImageList#map to allow the use of the Enumerable/Array#map method on ImageList objects.

[Source]

      # File lib/RMagick.rb, line 1443
1443:     def __map__(&block)
1444:         cfid = self[@scene].__id__ rescue nil
1445:         ensure_image = Proc.new do |img|
1446:             rv = block.call(img)
1447:             is_a_image rv
1448:             return rv
1449:         end
1450:         a = self.class.new.replace __ary_map__(&ensure_image)
1451:         a.set_cf cfid
1452:         return a
1453:     end

[Source]

      # File lib/RMagick.rb, line 1351
1351:     def clear
1352:         @scene = nil
1353:         super
1354:     end

[Source]

      # File lib/RMagick.rb, line 1599
1599:     def clone
1600:         ditto = dup
1601:         ditto.freeze if frozen?
1602:         return ditto
1603:     end

[Source]

      # File lib/RMagick.rb, line 1356
1356:     def collect(&block)
1357:         cfid = self[@scene].__id__ rescue nil
1358:         a = self.class.new.replace super
1359:         a.set_cf cfid
1360:         return a
1361:     end

[Source]

      # File lib/RMagick.rb, line 1363
1363:     def collect!(&block)
1364:         super
1365:         is_a_image_array self
1366:         self
1367:     end

[Source]

      # File lib/RMagick.rb, line 1369
1369:     def compact
1370:         cfid = self[@scene].__id__ rescue nil
1371:         a = self.class.new.replace super
1372:         a.set_cf cfid
1373:         return a
1374:     end

[Source]

      # File lib/RMagick.rb, line 1376
1376:     def compact!
1377:         cfid = self[@scene].__id__ rescue nil
1378:         a = super          # returns nil if no changes were made
1379:         set_cf cfid
1380:         return a
1381:     end

[Source]

      # File lib/RMagick.rb, line 1383
1383:     def concat(other)
1384:         is_a_image_array other
1385:         a = super
1386:         @scene = length-1
1387:         return a
1388:     end

Make a deep copy

[Source]

      # File lib/RMagick.rb, line 1606
1606:     def copy
1607:         ditto = self.class.new
1608:         each { |f| ditto << f.copy }
1609:         ditto.scene = @scene
1610:         ditto.taint if tainted?
1611:         return ditto
1612:     end

Return the current image

[Source]

      # File lib/RMagick.rb, line 1615
1615:     def cur_image
1616:         if ! @scene
1617:             Kernel.raise IndexError, "no images in this list"
1618:         end
1619:         self[@scene]
1620:     end

Set same delay for all images

[Source]

      # File lib/RMagick.rb, line 1623
1623:     def delay=(d)
1624:         if Integer(d) < 0
1625:             raise ArgumentError, "delay must be greater than or equal to 0"
1626:         end
1627:         each { |f| f.delay = Integer(d) }
1628:     end

[Source]

      # File lib/RMagick.rb, line 1390
1390:     def delete(obj, &block)
1391:         is_a_image obj
1392:         cfid = self[@scene].__id__ rescue nil
1393:         a = super
1394:         set_cf cfid
1395:         return a
1396:     end

[Source]

      # File lib/RMagick.rb, line 1398
1398:     def delete_at(ndx)
1399:         cfid = self[@scene].__id__ rescue nil
1400:         a = super
1401:         set_cf cfid
1402:         return a
1403:     end

[Source]

      # File lib/RMagick.rb, line 1405
1405:     def delete_if(&block)
1406:         cfid = self[@scene].__id__ rescue nil
1407:         a = super
1408:         set_cf cfid
1409:         return a
1410:     end

[Source]

      # File lib/RMagick.rb, line 1637
1637:     def dup
1638:         ditto = self.class.new
1639:         each {|img| ditto << img}
1640:         ditto.scene = @scene
1641:         ditto.taint if tainted?
1642:         return ditto
1643:     end

[Source]

      # File lib/RMagick.rb, line 1412
1412:     def fill(*args, &block)
1413:         is_a_image args[0] unless block_given?
1414:         cfid = self[@scene].__id__ rescue nil
1415:         super
1416:         is_a_image_array self
1417:         set_cf cfid
1418:         return self
1419:     end

[Source]

      # File lib/RMagick.rb, line 1421
1421:     def find_all(&block)
1422:         cfid = self[@scene].__id__ rescue nil
1423:         a = super
1424:         a.set_cf cfid
1425:         return a
1426:     end

[Source]

      # File lib/RMagick.rb, line 1645
1645:     def from_blob(*blobs, &block)
1646:         if (blobs.length == 0)
1647:             Kernel.raise ArgumentError, "no blobs given"
1648:         end
1649:         blobs.each { |b|
1650:             Magick::Image.from_blob(b, &block).each { |n| self << n  }
1651:             }
1652:         @scene = length - 1
1653:         self
1654:     end

[Source]

      # File lib/RMagick.rb, line 1429
1429:         def insert(*args)
1430:             Kernel.raise(ArgumentError, "can't insert nil") unless args.length > 1
1431:             is_a_image_array args[1,args.length-1]
1432:             cfid = self[@scene].__id__ rescue nil
1433:             super
1434:             set_cf cfid
1435:             return self
1436:         end

Call inspect for all the images

[Source]

      # File lib/RMagick.rb, line 1669
1669:     def inspect
1670:         ins = '['
1671:         each {|image| ins << image.inspect << "\n"}
1672:         ins.chomp("\n") + "]\nscene=#{@scene}"
1673:     end

Set the number of iterations of an animated GIF

[Source]

      # File lib/RMagick.rb, line 1676
1676:     def iterations=(n)
1677:         n = Integer(n)
1678:         if n < 0 || n > 65535
1679:             Kernel.raise ArgumentError, "iterations must be between 0 and 65535"
1680:         end
1681:         each {|f| f.iterations=n}
1682:         self
1683:     end

[Source]

      # File lib/RMagick.rb, line 1455
1455:     def map!(&block)
1456:         ensure_image = Proc.new do |img|
1457:             rv = block.call(img)
1458:             is_a_image rv
1459:             return rv
1460:         end
1461:         super(&ensure_image)
1462:     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 1689
1689:     def method_missing(methID, *args, &block)
1690:         begin
1691:             if @scene
1692:                 self[@scene].send(methID, *args, &block)
1693:             else
1694:                 super
1695:             end
1696:         rescue NoMethodError
1697:           Kernel.raise NoMethodError, "undefined method `#{methID.id2name}' for #{self.class}"
1698:         rescue Exception
1699:             $@.delete_if { |s| /:in `send'$/.match(s) || /:in `method_missing'$/.match(s) }
1700:             Kernel.raise
1701:         end
1702:     end

Create a new image and add it to the end

[Source]

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

Ping files and concatenate the new images

[Source]

      # File lib/RMagick.rb, line 1721
1721:     def ping(*files, &block)
1722:         if (files.length == 0)
1723:             Kernel.raise ArgumentError, "no files given"
1724:         end
1725:         files.each { |f|
1726:             Magick::Image.ping(f, &block).each { |n| self << n }
1727:             }
1728:         @scene = length - 1
1729:         self
1730:     end

[Source]

      # File lib/RMagick.rb, line 1464
1464:     def pop
1465:         cfid = self[@scene].__id__ rescue nil
1466:         a = super       # can return nil
1467:         set_cf cfid
1468:         return a
1469:     end

[Source]

      # File lib/RMagick.rb, line 1471
1471:     def push(*objs)
1472:         objs.each { |o| is_a_image o }
1473:         super
1474:         @scene = length - 1
1475:         self
1476:     end

Read files and concatenate the new images

[Source]

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

[Source]

      # File lib/RMagick.rb, line 1478
1478:     def reject(&block)
1479:         cfid = self[@scene].__id__ rescue nil
1480:         a = self.class.new.replace super
1481:         a.set_cf cfid
1482:         return a
1483:     end

[Source]

      # File lib/RMagick.rb, line 1485
1485:     def reject!(&block)
1486:         cfid = self[@scene].__id__ rescue nil
1487:         a = super       # can return nil
1488:         set_cf cfid
1489:         return a
1490:     end

[Source]

      # File lib/RMagick.rb, line 1492
1492:     def replace(other)
1493:         is_a_image_array other
1494:         # Since replace gets called so frequently when @scene == nil
1495:         # test for it instead of letting rescue catch it.
1496:         cfid = nil
1497:         if @scene then
1498:             cfid = self[@scene].__id__ rescue nil
1499:         end
1500:         super
1501:         # set_cf will fail if the new list has fewer images
1502:         # than the scene number indicates.
1503:         @scene = self.length == 0 ? nil : 0
1504:         set_cf cfid
1505:         self
1506:     end

[Source]

      # File lib/RMagick.rb, line 1706
1706:     def respond_to?(methID, priv=false)
1707:         return true if __respond_to__?(methID, priv)
1708:         if @scene
1709:             self[@scene].respond_to?(methID, priv)
1710:         else
1711:             super
1712:         end
1713:     end

[Source]

      # File lib/RMagick.rb, line 1508
1508:     def reverse
1509:         cfid = self[@scene].__id__ rescue nil
1510:         a = self.class.new.replace super
1511:         a.set_cf cfid
1512:         return a
1513:     end

[Source]

      # File lib/RMagick.rb, line 1515
1515:     def reverse!
1516:         cfid = self[@scene].__id__ rescue nil
1517:         a = super
1518:         set_cf cfid
1519:         return a
1520:     end

Allow scene to be set to nil

[Source]

      # File lib/RMagick.rb, line 1255
1255:     def scene=(n)
1256:         if n.nil?
1257:             Kernel.raise IndexError, "scene number out of bounds" unless length == 0
1258:             @scene = nil
1259:             return @scene
1260:         elsif length == 0
1261:             Kernel.raise IndexError, "scene number out of bounds"
1262:         end
1263: 
1264:         n = Integer(n)
1265:         if n < 0 || n > length - 1
1266:             Kernel.raise IndexError, "scene number out of bounds"
1267:         end
1268:         @scene = n
1269:         return @scene
1270:     end

[Source]

      # File lib/RMagick.rb, line 1522
1522:     def select(&block)
1523:         cfid = self[@scene].__id__ rescue nil
1524:         a = self.class.new.replace super
1525:         a.set_cf cfid
1526:         return a
1527:     end

[Source]

      # File lib/RMagick.rb, line 1529
1529:     def shift
1530:         cfid = self[@scene].__id__ rescue nil
1531:         a = super
1532:         set_cf cfid
1533:         return a
1534:     end

[Source]

      # File lib/RMagick.rb, line 1536
1536:     def slice(*args)
1537:         self[*args]
1538:     end

[Source]

      # File lib/RMagick.rb, line 1540
1540:     def slice!(*args)
1541:         cfid = self[@scene].__id__ rescue nil
1542:         if args.length > 1 || args[0].kind_of?(Range)
1543:             a = self.class.new.replace super
1544:         else
1545:             a = super
1546:         end
1547:         set_cf cfid
1548:         return a
1549:     end

[Source]

      # File lib/RMagick.rb, line 1630
1630:     def ticks_per_second=(t)
1631:         if Integer(t) < 0
1632:             Kernel.raise ArgumentError, "ticks_per_second must be greater than or equal to 0"
1633:         end
1634:         each { |f| f.ticks_per_second = Integer(t) }
1635:     end

[Source]

      # File lib/RMagick.rb, line 1551
1551:     def uniq
1552:         cfid = self[@scene].__id__ rescue nil
1553:         a = self.class.new.replace super
1554:         a.set_cf cfid
1555:         return a
1556:     end

[Source]

      # File lib/RMagick.rb, line 1558
1558:     def uniq!(*args)
1559:         cfid = self[@scene].__id__ rescue nil
1560:         a = super
1561:         set_cf cfid
1562:         return a
1563:     end

@scene -> new object

[Source]

      # File lib/RMagick.rb, line 1566
1566:     def unshift(obj)
1567:         is_a_image obj
1568:         a = super
1569:         @scene = 0
1570:         return a
1571:     end

[Source]

      # File lib/RMagick.rb, line 1343
1343:     def |(other)
1344:         is_a_image_array other
1345:         cfid = self[@scene].__id__ rescue nil
1346:         a = self.class.new.replace super
1347:         a.set_cf cfid
1348:         return a
1349:     end

Protected Instance methods

[Source]

      # File lib/RMagick.rb, line 1215
1215:     def is_a_image(obj)
1216:         unless obj.kind_of? Magick::Image
1217:             Kernel.raise ArgumentError, "Magick::Image required (#{obj.class} given)"
1218:         end
1219:         true
1220:     end

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

[Source]

      # File lib/RMagick.rb, line 1223
1223:     def is_a_image_array(ary)
1224:         unless ary.respond_to? :each
1225:             Kernel.raise ArgumentError, "Magick::ImageList or array of Magick::Images required (#{ary.class} given)"
1226:         end
1227:         ary.each { |obj| is_a_image obj }
1228:         true
1229:     end

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

[Source]

      # File lib/RMagick.rb, line 1233
1233:     def set_cf(cfid)
1234:         if length == 0
1235:             @scene = nil
1236:             return
1237:         # Don't bother looking for current image
1238:         elsif @scene == nil || @scene >= length
1239:             @scene = length - 1
1240:             return
1241:         elsif cfid != nil
1242:             each_with_index do |f,i|
1243:                 if f.__id__ == cfid
1244:                     @scene = i
1245:                     return
1246:                 end
1247:             end
1248:         end
1249:         @scene = length - 1
1250:     end

[Validate]