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/units.rb Magick Module: Magick

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 1520
1520:     def initialize(*filenames)
1521:         @scene = nil
1522:         filenames.each { |f|
1523:             Magick::Image.read(f).each { |n| self << n }
1524:             }
1525:         if length > 0
1526:             @scene = length - 1     # last image in array
1527:         end
1528:         self
1529:     end

Public Instance methods

[Source]

      # File lib/RMagick.rb, line 1166
1166:     def &(other)
1167:         is_a_image_array other
1168:         cfid = self[@scene].__id__ rescue nil
1169:         a = self.class.new.replace super
1170:         a.set_cf cfid
1171:         return a
1172:     end

[Source]

      # File lib/RMagick.rb, line 1174
1174:     def *(n)
1175:         unless n.kind_of? Integer
1176:             raise ArgumentError, "Integer required (#{n.class} given)"
1177:         end
1178:         cfid = self[@scene].__id__ rescue nil
1179:         a = self.class.new.replace super
1180:         a.set_cf cfid
1181:         return a
1182:     end

[Source]

      # File lib/RMagick.rb, line 1184
1184:     def +(other)
1185:         cfid = self[@scene].__id__ rescue nil
1186:         a = self.class.new.replace super
1187:         a.set_cf cfid
1188:         return a
1189:     end

[Source]

      # File lib/RMagick.rb, line 1191
1191:     def -(other)
1192:         is_a_image_array other
1193:         cfid = self[@scene].__id__ rescue nil
1194:         a = self.class.new.replace super
1195:         a.set_cf cfid
1196:         return a
1197:     end

[Source]

      # File lib/RMagick.rb, line 1199
1199:     def <<(obj)
1200:         is_a_image obj
1201:         a = super
1202:         @scene = length-1
1203:         return a
1204:     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 1441
1441:     def <=>(other)
1442:         unless other.kind_of? self.class
1443:            raise TypeError, "#{self.class} required (#{other.class} given)"
1444:         end
1445:         size = [self.length, other.length].min
1446:         size.times do |x|
1447:             r = self[x] <=> other[x]
1448:             return r unless r == 0
1449:         end
1450:         if @scene.nil? && other.scene.nil?
1451:             return 0
1452:         elsif @scene.nil? && ! other.scene.nil?
1453:             raise TypeError, "cannot convert nil into #{other.scene.class}"
1454:         elsif ! @scene.nil? && other.scene.nil?
1455:             raise TypeError, "cannot convert nil into #{self.scene.class}"
1456:         end
1457:         r = self.scene <=> other.scene
1458:         return r unless r == 0
1459:         return self.length <=> other.length
1460:     end

[Source]

      # File lib/RMagick.rb, line 1135
1135:     def [](*args)
1136:         if (args.length > 1) || args[0].kind_of?(Range)
1137:             self.class.new.replace super
1138:         else
1139:             super
1140:         end
1141:     end

[Source]

      # File lib/RMagick.rb, line 1143
1143:     def []=(*args)
1144:         if args.length == 3             # f[start,length] = [f1,f2...]
1145:             args[2].kind_of?(Magick::Image) || is_a_image_array(args[2])
1146:             super
1147:             args[0] = args[0] + length if (args[0] < 0)
1148:             args[1] = length - args[0] if (args[0] + args[1] > length)
1149:             if args[2].kind_of?(Magick::Image)
1150:                 @scene = args[0]
1151:             else
1152:                 @scene = args[0] + args[2].length - 1
1153:             end
1154:         elsif args[0].kind_of? Range    # f[first..last] = [f1,f2...]
1155:             args[1].kind_of?(Magick::Image) || is_a_image_array(args[1])
1156:             super
1157:             @scene = args[0].end
1158:         else                            # f[index] = f1
1159:             is_a_image args[1]
1160:             super                       # index can be negative
1161:             @scene = args[0] < 0 ? length + args[0] : args[0]
1162:         end
1163:         args.last                       # return value is always assigned value
1164:     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 1306
1306:     def __map__(&block)
1307:         cfid = self[@scene].__id__ rescue nil
1308:         ensure_image = Proc.new do |img|
1309:             rv = block.call(img)
1310:             is_a_image rv
1311:             return rv
1312:         end
1313:         a = self.class.new.replace __ary_map__(&ensure_image)
1314:         a.set_cf cfid
1315:         return a
1316:     end

[Source]

      # File lib/RMagick.rb, line 1214
1214:     def clear
1215:         @scene = nil
1216:         super
1217:     end

[Source]

      # File lib/RMagick.rb, line 1462
1462:     def clone
1463:         ditto = dup
1464:         ditto.freeze if frozen?
1465:         return ditto
1466:     end

[Source]

      # File lib/RMagick.rb, line 1219
1219:     def collect(&block)
1220:         cfid = self[@scene].__id__ rescue nil
1221:         a = self.class.new.replace super
1222:         a.set_cf cfid
1223:         return a
1224:     end

[Source]

      # File lib/RMagick.rb, line 1226
1226:     def collect!(&block)
1227:         super
1228:         is_a_image_array self
1229:         self
1230:     end

[Source]

      # File lib/RMagick.rb, line 1232
1232:     def compact
1233:         cfid = self[@scene].__id__ rescue nil
1234:         a = self.class.new.replace super
1235:         a.set_cf cfid
1236:         return a
1237:     end

[Source]

      # File lib/RMagick.rb, line 1239
1239:     def compact!
1240:         cfid = self[@scene].__id__ rescue nil
1241:         a = super          # returns nil if no changes were made
1242:         set_cf cfid
1243:         return a
1244:     end

[Source]

      # File lib/RMagick.rb, line 1246
1246:     def concat(other)
1247:         is_a_image_array other
1248:         a = super
1249:         @scene = length-1
1250:         return a
1251:     end

Make a deep copy

[Source]

      # File lib/RMagick.rb, line 1469
1469:     def copy
1470:         ditto = self.class.new
1471:         each { |f| ditto << f.copy }
1472:         ditto.scene = @scene
1473:         ditto.taint if tainted?
1474:         return ditto
1475:     end

Return the current image

[Source]

      # File lib/RMagick.rb, line 1478
1478:     def cur_image
1479:         if ! @scene
1480:             raise IndexError, "no images in this list"
1481:         end
1482:         self[@scene]
1483:     end

Set same delay for all images

[Source]

      # File lib/RMagick.rb, line 1486
1486:     def delay=(d)
1487:         if Integer(d) < 0
1488:             raise ArgumentError, "delay must be greater than or equal to 0"
1489:         end
1490:         each { |f| f.delay = Integer(d) }
1491:     end

[Source]

      # File lib/RMagick.rb, line 1253
1253:     def delete(obj, &block)
1254:         is_a_image obj
1255:         cfid = self[@scene].__id__ rescue nil
1256:         a = super
1257:         set_cf cfid
1258:         return a
1259:     end

[Source]

      # File lib/RMagick.rb, line 1261
1261:     def delete_at(ndx)
1262:         cfid = self[@scene].__id__ rescue nil
1263:         a = super
1264:         set_cf cfid
1265:         return a
1266:     end

[Source]

      # File lib/RMagick.rb, line 1268
1268:     def delete_if(&block)
1269:         cfid = self[@scene].__id__ rescue nil
1270:         a = super
1271:         set_cf cfid
1272:         return a
1273:     end

[Source]

      # File lib/RMagick.rb, line 1500
1500:     def dup
1501:         ditto = self.class.new
1502:         each {|img| ditto << img}
1503:         ditto.scene = @scene
1504:         ditto.taint if tainted?
1505:         return ditto
1506:     end

[Source]

      # File lib/RMagick.rb, line 1275
1275:     def fill(*args, &block)
1276:         is_a_image args[0] unless block_given?
1277:         cfid = self[@scene].__id__ rescue nil
1278:         super
1279:         is_a_image_array self
1280:         set_cf cfid
1281:         return self
1282:     end

[Source]

      # File lib/RMagick.rb, line 1284
1284:     def find_all(&block)
1285:         cfid = self[@scene].__id__ rescue nil
1286:         a = super
1287:         a.set_cf cfid
1288:         return a
1289:     end

[Source]

      # File lib/RMagick.rb, line 1508
1508:     def from_blob(*blobs, &block)
1509:         if (blobs.length == 0)
1510:             raise ArgumentError, "no blobs given"
1511:         end
1512:         blobs.each { |b|
1513:             Magick::Image.from_blob(b, &block).each { |n| self << n  }
1514:             }
1515:         @scene = length - 1
1516:         self
1517:     end

[Source]

      # File lib/RMagick.rb, line 1292
1292:         def insert(*args)
1293:             raise(ArgumentError, "can't insert nil") unless args.length > 1
1294:             is_a_image_array args[1,args.length-1]
1295:             cfid = self[@scene].__id__ rescue nil
1296:             super
1297:             set_cf cfid
1298:             return self
1299:         end

Call inspect for all the images

[Source]

      # File lib/RMagick.rb, line 1532
1532:     def inspect
1533:         ins = '['
1534:         each {|image| ins << image.inspect << "\n"}
1535:         ins.chomp("\n") + "]\nscene=#{@scene}"
1536:     end

Set the number of iterations of an animated GIF

[Source]

      # File lib/RMagick.rb, line 1539
1539:     def iterations=(n)
1540:         n = Integer(n)
1541:         if n < 0 || n > 65535
1542:             raise ArgumentError, "iterations must be between 0 and 65535"
1543:         end
1544:         each {|f| f.iterations=n}
1545:         self
1546:     end

[Source]

      # File lib/RMagick.rb, line 1318
1318:     def map!(&block)
1319:         ensure_image = Proc.new do |img|
1320:             rv = block.call(img)
1321:             is_a_image rv
1322:             return rv
1323:         end
1324:         super(&ensure_image)
1325:     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 1552
1552:     def method_missing(methID, *args, &block)
1553:         begin
1554:             if @scene
1555:                 self[@scene].send(methID, *args, &block)
1556:             else
1557:                 super
1558:             end
1559:         rescue NoMethodError
1560:           raise NoMethodError, "undefined method `#{methID.id2name}' for #{self.class}"
1561:         rescue Exception
1562:             $@.delete_if { |s| /:in `send'$/.match(s) || /:in `method_missing'$/.match(s) }
1563:             raise
1564:         end
1565:     end

Create a new image and add it to the end

[Source]

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

Ping files and concatenate the new images

[Source]

      # File lib/RMagick.rb, line 1584
1584:     def ping(*files, &block)
1585:         if (files.length == 0)
1586:             raise ArgumentError, "no files given"
1587:         end
1588:         files.each { |f|
1589:             Magick::Image.ping(f, &block).each { |n| self << n }
1590:             }
1591:         @scene = length - 1
1592:         self
1593:     end

[Source]

      # File lib/RMagick.rb, line 1327
1327:     def pop
1328:         cfid = self[@scene].__id__ rescue nil
1329:         a = super       # can return nil
1330:         set_cf cfid
1331:         return a
1332:     end

[Source]

      # File lib/RMagick.rb, line 1334
1334:     def push(*objs)
1335:         objs.each { |o| is_a_image o }
1336:         super
1337:         @scene = length - 1
1338:         self
1339:     end

Read files and concatenate the new images

[Source]

      # File lib/RMagick.rb, line 1596
1596:     def read(*files, &block)
1597:         if (files.length == 0)
1598:             raise ArgumentError, "no files given"
1599:         end
1600:         files.each { |f|
1601:             Magick::Image.read(f, &block).each { |n| self << n }
1602:             }
1603:         @scene = length - 1
1604:         self
1605:     end

[Source]

      # File lib/RMagick.rb, line 1341
1341:     def reject(&block)
1342:         cfid = self[@scene].__id__ rescue nil
1343:         a = self.class.new.replace super
1344:         a.set_cf cfid
1345:         return a
1346:     end

[Source]

      # File lib/RMagick.rb, line 1348
1348:     def reject!(&block)
1349:         cfid = self[@scene].__id__ rescue nil
1350:         a = super       # can return nil
1351:         set_cf cfid
1352:         return a
1353:     end

[Source]

      # File lib/RMagick.rb, line 1355
1355:     def replace(other)
1356:         is_a_image_array other
1357:         # Since replace gets called so frequently when @scene == nil
1358:         # test for it instead of letting rescue catch it.
1359:         cfid = nil
1360:         if @scene then
1361:             cfid = self[@scene].__id__ rescue nil
1362:         end
1363:         super
1364:         # set_cf will fail if the new list has fewer images
1365:         # than the scene number indicates.
1366:         @scene = self.length == 0 ? nil : 0
1367:         set_cf cfid
1368:         self
1369:     end

[Source]

      # File lib/RMagick.rb, line 1569
1569:     def respond_to?(methID, priv=false)
1570:         return true if __respond_to__?(methID, priv)
1571:         if @scene
1572:             self[@scene].respond_to?(methID, priv)
1573:         else
1574:             super
1575:         end
1576:     end

[Source]

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

[Source]

      # File lib/RMagick.rb, line 1378
1378:     def reverse!
1379:         cfid = self[@scene].__id__ rescue nil
1380:         a = super
1381:         set_cf cfid
1382:         return a
1383:     end

Allow scene to be set to nil

[Source]

      # File lib/RMagick.rb, line 1118
1118:     def scene=(n)
1119:         if n.nil?
1120:             raise IndexError, "scene number out of bounds" unless length == 0
1121:             @scene = nil
1122:             return @scene
1123:         elsif length == 0
1124:             raise IndexError, "scene number out of bounds"
1125:         end
1126: 
1127:         n = Integer(n)
1128:         if n < 0 || n > length - 1
1129:             raise IndexError, "scene number out of bounds"
1130:         end
1131:         @scene = n
1132:         return @scene
1133:     end

[Source]

      # File lib/RMagick.rb, line 1385
1385:     def select(&block)
1386:         cfid = self[@scene].__id__ rescue nil
1387:         a = self.class.new.replace super
1388:         a.set_cf cfid
1389:         return a
1390:     end

[Source]

      # File lib/RMagick.rb, line 1392
1392:     def shift
1393:         cfid = self[@scene].__id__ rescue nil
1394:         a = super
1395:         set_cf cfid
1396:         return a
1397:     end

[Source]

      # File lib/RMagick.rb, line 1399
1399:     def slice(*args)
1400:         self[*args]
1401:     end

[Source]

      # File lib/RMagick.rb, line 1403
1403:     def slice!(*args)
1404:         cfid = self[@scene].__id__ rescue nil
1405:         if args.length > 1 || args[0].kind_of?(Range)
1406:             a = self.class.new.replace super
1407:         else
1408:             a = super
1409:         end
1410:         set_cf cfid
1411:         return a
1412:     end

[Source]

      # File lib/RMagick.rb, line 1493
1493:     def ticks_per_second=(t)
1494:         if Integer(t) < 0
1495:             raise ArgumentError, "ticks_per_second must be greater than or equal to 0"
1496:         end
1497:         each { |f| f.ticks_per_second = Integer(t) }
1498:     end

[Source]

      # File lib/RMagick.rb, line 1414
1414:     def uniq
1415:         cfid = self[@scene].__id__ rescue nil
1416:         a = self.class.new.replace super
1417:         a.set_cf cfid
1418:         return a
1419:     end

[Source]

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

@scene -> new object

[Source]

      # File lib/RMagick.rb, line 1429
1429:     def unshift(obj)
1430:         is_a_image obj
1431:         a = super
1432:         @scene = 0
1433:         return a
1434:     end

[Source]

      # File lib/RMagick.rb, line 1206
1206:     def |(other)
1207:         is_a_image_array other
1208:         cfid = self[@scene].__id__ rescue nil
1209:         a = self.class.new.replace super
1210:         a.set_cf cfid
1211:         return a
1212:     end

Protected Instance methods

[Source]

      # File lib/RMagick.rb, line 1078
1078:     def is_a_image(obj)
1079:         unless obj.kind_of? Magick::Image
1080:             raise ArgumentError, "Magick::Image required (#{obj.class} given)"
1081:         end
1082:         true
1083:     end

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

[Source]

      # File lib/RMagick.rb, line 1086
1086:     def is_a_image_array(ary)
1087:         unless ary.respond_to? :each
1088:             raise ArgumentError, "Magick::ImageList or array of Magick::Images required (#{ary.class} given)"
1089:         end
1090:         ary.each { |obj| is_a_image obj }
1091:         true
1092:     end

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

[Source]

      # File lib/RMagick.rb, line 1096
1096:     def set_cf(cfid)
1097:         if length == 0
1098:             @scene = nil
1099:             return
1100:         # Don't bother looking for current image
1101:         elsif @scene == nil || @scene >= length
1102:             @scene = length - 1
1103:             return
1104:         elsif cfid != nil
1105:             each_with_index do |f,i|
1106:                 if f.__id__ == cfid
1107:                     @scene = i
1108:                     return
1109:                 end
1110:             end
1111:         end
1112:         @scene = length - 1
1113:     end

[Validate]