Class: Magick::ImageList
- Inherits:
-
Array
- Object
- Array
- Magick::ImageList
show all
- Includes:
- Comparable
- Defined in:
- lib/RMagick.rb,
ext/RMagick/rmmain.c
Overview
Defined Under Namespace
Classes: Montage
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#&(other) ⇒ Object
-
#*(n) ⇒ Object
-
#+(other) ⇒ Object
-
#-(other) ⇒ Object
-
#<<(obj) ⇒ Object
-
#<=>(other) ⇒ Object
Compare ImageLists Compare each image in turn until the result of a comparison is not 0.
-
#[](*args) ⇒ Object
-
#[]=(*args) ⇒ Object
-
#__map__(&block) ⇒ Object
Enumerable (or Array) has a #map method that conflicts with our own #map method.
-
#__respond_to__? ⇒ Object
Ensure respond_to? answers correctly when we are delegating to Image.
-
#animate ⇒ Object
-
#append ⇒ Object
-
#average ⇒ Object
-
#clear ⇒ Object
-
#clone ⇒ Object
-
#coalesce ⇒ Object
-
#collect(&block) ⇒ Object
-
#collect!(&block) ⇒ Object
-
#compact ⇒ Object
-
#compact! ⇒ Object
-
#concat(other) ⇒ Object
-
#copy ⇒ Object
-
#cur_image ⇒ Object
Return the current image.
-
#deconstruct ⇒ Object
-
#delay=(d) ⇒ Object
Set same delay for all images.
-
#delete(obj, &block) ⇒ Object
-
#delete_at(ndx) ⇒ Object
-
#delete_if(&block) ⇒ Object
-
#display ⇒ Object
(also: #__display__)
-
#dup ⇒ Object
-
#fill(*args, &block) ⇒ Object
-
#find_all(&block) ⇒ Object
-
#flatten_images ⇒ Object
-
#from_blob(*blobs, &block) ⇒ Object
-
#fx ⇒ Object
-
#initialize(*filenames) ⇒ ImageList
constructor
Initialize new instances.
-
#insert(*args) ⇒ Object
-
#inspect ⇒ Object
Call inspect for all the images.
-
#iterations=(n) ⇒ Object
Set the number of iterations of an animated GIF.
-
#map ⇒ Object
(also: #__ary_map__)
-
#map!(&block) ⇒ Object
-
#method_missing(methID, *args, &block) ⇒ Object
The ImageList class supports the Magick::Image class methods by simply sending the method to the current image.
-
#montage ⇒ Object
-
#morph ⇒ Object
-
#mosaic ⇒ Object
-
#new_image(cols, rows, *fill, &info_blk) ⇒ Object
Create a new image and add it to the end.
-
#optimize_layers ⇒ Object
-
#ping(*files, &block) ⇒ Object
Ping files and concatenate the new images.
-
#pop ⇒ Object
-
#push(*objs) ⇒ Object
-
#quantize ⇒ Object
-
#read(*files, &block) ⇒ Object
Read files and concatenate the new images.
-
#reject(&block) ⇒ Object
-
#reject!(&block) ⇒ Object
-
#replace(other) ⇒ Object
-
#respond_to?(methID, priv = false) ⇒ Boolean
-
#reverse ⇒ Object
-
#reverse! ⇒ Object
-
#select(&block) ⇒ Object
-
#shift ⇒ Object
-
#slice(*args) ⇒ Object
-
#slice!(*args) ⇒ Object
-
#ticks_per_second=(t) ⇒ Object
-
#to_blob ⇒ Object
-
#uniq ⇒ Object
-
#uniq!(*args) ⇒ Object
-
#unshift(obj) ⇒ Object
-
#write ⇒ Object
-
#|(other) ⇒ Object
Constructor Details
#initialize(*filenames) ⇒ ImageList
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
|
# File 'lib/RMagick.rb', line 1656
def initialize(*filenames)
@scene = nil
filenames.each { |f|
Magick::Image.read(f).each { |n| self << n }
}
if length > 0
@scene = length - 1 end
self
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(methID, *args, &block) ⇒ Object
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.
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
|
# File 'lib/RMagick.rb', line 1688
def method_missing(methID, *args, &block)
begin
if @scene
self[@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
|
Instance Attribute Details
#scene ⇒ Object
Returns the value of attribute scene.
1210
1211
1212
|
# File 'lib/RMagick.rb', line 1210
def scene
@scene
end
|
Instance Method Details
#&(other) ⇒ Object
1302
1303
1304
1305
1306
1307
1308
|
# File 'lib/RMagick.rb', line 1302
def &(other)
is_a_image_array other
cfid = self[@scene].__id__ rescue nil
a = self.class.new.replace super
a.set_cf cfid
return a
end
|
#*(n) ⇒ Object
1310
1311
1312
1313
1314
1315
1316
1317
1318
|
# File 'lib/RMagick.rb', line 1310
def *(n)
unless n.kind_of? Integer
Kernel.raise ArgumentError, "Integer required (#{n.class} given)"
end
cfid = self[@scene].__id__ rescue nil
a = self.class.new.replace super
a.set_cf cfid
return a
end
|
#+(other) ⇒ Object
1320
1321
1322
1323
1324
1325
|
# File 'lib/RMagick.rb', line 1320
def +(other)
cfid = self[@scene].__id__ rescue nil
a = self.class.new.replace super
a.set_cf cfid
return a
end
|
#-(other) ⇒ Object
1327
1328
1329
1330
1331
1332
1333
|
# File 'lib/RMagick.rb', line 1327
def -(other)
is_a_image_array other
cfid = self[@scene].__id__ rescue nil
a = self.class.new.replace super
a.set_cf cfid
return a
end
|
#<<(obj) ⇒ Object
1335
1336
1337
1338
1339
1340
|
# File 'lib/RMagick.rb', line 1335
def <<(obj)
is_a_image obj
a = super
@scene = length-1
return a
end
|
#<=>(other) ⇒ Object
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
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
|
# File 'lib/RMagick.rb', line 1577
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) ⇒ Object
1271
1272
1273
1274
1275
1276
1277
|
# File 'lib/RMagick.rb', line 1271
def [](*args)
if (args.length > 1) || args[0].kind_of?(Range)
self.class.new.replace super
else
super
end
end
|
#[]=(*args) ⇒ Object
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
|
# File 'lib/RMagick.rb', line 1279
def []=(*args)
if args.length == 3 args[2].kind_of?(Magick::Image) || is_a_image_array(args[2])
super
args[0] = args[0] + length if (args[0] < 0)
args[1] = length - args[0] if (args[0] + args[1] > length)
if args[2].kind_of?(Magick::Image)
@scene = args[0]
else
@scene = args[0] + args[2].length - 1
end
elsif args[0].kind_of? Range args[1].kind_of?(Magick::Image) || is_a_image_array(args[1])
super
@scene = args[0].end
else is_a_image args[1]
super @scene = args[0] < 0 ? length + args[0] : args[0]
end
args.last end
|
#__map__(&block) ⇒ Object
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.
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
|
# File 'lib/RMagick.rb', line 1442
def __map__(&block)
cfid = self[@scene].__id__ rescue nil
ensure_image = Proc.new do |img|
rv = block.call(img)
is_a_image rv
return rv
end
a = self.class.new.replace __ary_map__(&ensure_image)
a.set_cf cfid
return a
end
|
#__respond_to__? ⇒ Object
Ensure respond_to? answers correctly when we are delegating to Image
1704
|
# File 'lib/RMagick.rb', line 1704
alias_method :__respond_to__?, :respond_to?
|
#animate ⇒ Object
#append ⇒ Object
#average ⇒ Object
#clear ⇒ Object
1350
1351
1352
1353
|
# File 'lib/RMagick.rb', line 1350
def clear
@scene = nil
super
end
|
#clone ⇒ Object
1598
1599
1600
1601
1602
|
# File 'lib/RMagick.rb', line 1598
def clone
ditto = dup
ditto.freeze if frozen?
return ditto
end
|
#coalesce ⇒ Object
#collect(&block) ⇒ Object
1355
1356
1357
1358
1359
1360
|
# File 'lib/RMagick.rb', line 1355
def collect(&block)
cfid = self[@scene].__id__ rescue nil
a = self.class.new.replace super
a.set_cf cfid
return a
end
|
#collect!(&block) ⇒ Object
1362
1363
1364
1365
1366
|
# File 'lib/RMagick.rb', line 1362
def collect!(&block)
super
is_a_image_array self
self
end
|
#compact ⇒ Object
1368
1369
1370
1371
1372
1373
|
# File 'lib/RMagick.rb', line 1368
def compact
cfid = self[@scene].__id__ rescue nil
a = self.class.new.replace super
a.set_cf cfid
return a
end
|
#compact! ⇒ Object
1375
1376
1377
1378
1379
1380
|
# File 'lib/RMagick.rb', line 1375
def compact!
cfid = self[@scene].__id__ rescue nil
a = super set_cf cfid
return a
end
|
#concat(other) ⇒ Object
1382
1383
1384
1385
1386
1387
|
# File 'lib/RMagick.rb', line 1382
def concat(other)
is_a_image_array other
a = super
@scene = length-1
return a
end
|
#copy ⇒ Object
1605
1606
1607
1608
1609
1610
1611
|
# File 'lib/RMagick.rb', line 1605
def copy
ditto = self.class.new
each { |f| ditto << f.copy }
ditto.scene = @scene
ditto.taint if tainted?
return ditto
end
|
#cur_image ⇒ Object
1614
1615
1616
1617
1618
1619
|
# File 'lib/RMagick.rb', line 1614
def cur_image
if ! @scene
Kernel.raise IndexError, "no images in this list"
end
self[@scene]
end
|
#deconstruct ⇒ Object
#delay=(d) ⇒ Object
Set same delay for all images
1622
1623
1624
1625
1626
1627
|
# File 'lib/RMagick.rb', line 1622
def delay=(d)
if Integer(d) < 0
raise ArgumentError, "delay must be greater than or equal to 0"
end
each { |f| f.delay = Integer(d) }
end
|
#delete(obj, &block) ⇒ Object
1389
1390
1391
1392
1393
1394
1395
|
# File 'lib/RMagick.rb', line 1389
def delete(obj, &block)
is_a_image obj
cfid = self[@scene].__id__ rescue nil
a = super
set_cf cfid
return a
end
|
#delete_at(ndx) ⇒ Object
1397
1398
1399
1400
1401
1402
|
# File 'lib/RMagick.rb', line 1397
def delete_at(ndx)
cfid = self[@scene].__id__ rescue nil
a = super
set_cf cfid
return a
end
|
#delete_if(&block) ⇒ Object
1404
1405
1406
1407
1408
1409
|
# File 'lib/RMagick.rb', line 1404
def delete_if(&block)
cfid = self[@scene].__id__ rescue nil
a = super
set_cf cfid
return a
end
|
#display ⇒ Object
Also known as:
__display__
#dup ⇒ Object
1636
1637
1638
1639
1640
1641
1642
|
# File 'lib/RMagick.rb', line 1636
def dup
ditto = self.class.new
each {|img| ditto << img}
ditto.scene = @scene
ditto.taint if tainted?
return ditto
end
|
#fill(*args, &block) ⇒ Object
1411
1412
1413
1414
1415
1416
1417
1418
|
# File 'lib/RMagick.rb', line 1411
def fill(*args, &block)
is_a_image args[0] unless block_given?
cfid = self[@scene].__id__ rescue nil
super
is_a_image_array self
set_cf cfid
return self
end
|
#find_all(&block) ⇒ Object
1420
1421
1422
1423
1424
1425
|
# File 'lib/RMagick.rb', line 1420
def find_all(&block)
cfid = self[@scene].__id__ rescue nil
a = super
a.set_cf cfid
return a
end
|
#flatten_images ⇒ Object
#from_blob(*blobs, &block) ⇒ Object
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
|
# File 'lib/RMagick.rb', line 1644
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| self << n }
}
@scene = length - 1
self
end
|
#fx ⇒ Object
#insert(*args) ⇒ Object
1428
1429
1430
1431
1432
1433
1434
1435
|
# File 'lib/RMagick.rb', line 1428
def insert(*args)
Kernel.raise(ArgumentError, "can't insert nil") unless args.length > 1
is_a_image_array args[1,args.length-1]
cfid = self[@scene].__id__ rescue nil
super
set_cf cfid
return self
end
|
#inspect ⇒ Object
Call inspect for all the images
1668
1669
1670
1671
1672
|
# File 'lib/RMagick.rb', line 1668
def inspect
ins = '['
each {|image| ins << image.inspect << "\n"}
ins.chomp("\n") + "]\nscene=#{@scene}"
end
|
#iterations=(n) ⇒ Object
Set the number of iterations of an animated GIF
1675
1676
1677
1678
1679
1680
1681
1682
|
# File 'lib/RMagick.rb', line 1675
def iterations=(n)
n = Integer(n)
if n < 0 || n > 65535
Kernel.raise ArgumentError, "iterations must be between 0 and 65535"
end
each {|f| f.iterations=n}
self
end
|
#map ⇒ Object
Also known as:
__ary_map__
#map!(&block) ⇒ Object
1454
1455
1456
1457
1458
1459
1460
1461
|
# File 'lib/RMagick.rb', line 1454
def map!(&block)
ensure_image = Proc.new do |img|
rv = block.call(img)
is_a_image rv
return rv
end
super(&ensure_image)
end
|
#montage ⇒ Object
#morph ⇒ Object
#mosaic ⇒ Object
#new_image(cols, rows, *fill, &info_blk) ⇒ Object
Create a new image and add it to the end
1715
1716
1717
|
# File 'lib/RMagick.rb', line 1715
def new_image(cols, rows, *fill, &info_blk)
self << Magick::Image.new(cols, rows, *fill, &info_blk)
end
|
#optimize_layers ⇒ Object
#ping(*files, &block) ⇒ Object
Ping files and concatenate the new images
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
|
# File 'lib/RMagick.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| self << n }
}
@scene = length - 1
self
end
|
#pop ⇒ Object
1463
1464
1465
1466
1467
1468
|
# File 'lib/RMagick.rb', line 1463
def pop
cfid = self[@scene].__id__ rescue nil
a = super set_cf cfid
return a
end
|
#push(*objs) ⇒ Object
1470
1471
1472
1473
1474
1475
|
# File 'lib/RMagick.rb', line 1470
def push(*objs)
objs.each { |o| is_a_image o }
super
@scene = length - 1
self
end
|
#quantize ⇒ Object
#read(*files, &block) ⇒ Object
Read files and concatenate the new images
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
|
# File 'lib/RMagick.rb', line 1732
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| self << n }
}
@scene = length - 1
self
end
|
#reject(&block) ⇒ Object
1477
1478
1479
1480
1481
1482
|
# File 'lib/RMagick.rb', line 1477
def reject(&block)
cfid = self[@scene].__id__ rescue nil
a = self.class.new.replace super
a.set_cf cfid
return a
end
|
#reject!(&block) ⇒ Object
1484
1485
1486
1487
1488
1489
|
# File 'lib/RMagick.rb', line 1484
def reject!(&block)
cfid = self[@scene].__id__ rescue nil
a = super set_cf cfid
return a
end
|
#replace(other) ⇒ Object
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
|
# File 'lib/RMagick.rb', line 1491
def replace(other)
is_a_image_array other
cfid = nil
if @scene then
cfid = self[@scene].__id__ rescue nil
end
super
@scene = self.length == 0 ? nil : 0
set_cf cfid
self
end
|
#respond_to?(methID, priv = false) ⇒ Boolean
1705
1706
1707
1708
1709
1710
1711
1712
|
# File 'lib/RMagick.rb', line 1705
def respond_to?(methID, priv=false)
return true if __respond_to__?(methID, priv)
if @scene
self[@scene].respond_to?(methID, priv)
else
super
end
end
|
#reverse ⇒ Object
1507
1508
1509
1510
1511
1512
|
# File 'lib/RMagick.rb', line 1507
def reverse
cfid = self[@scene].__id__ rescue nil
a = self.class.new.replace super
a.set_cf cfid
return a
end
|
#reverse! ⇒ Object
1514
1515
1516
1517
1518
1519
|
# File 'lib/RMagick.rb', line 1514
def reverse!
cfid = self[@scene].__id__ rescue nil
a = super
set_cf cfid
return a
end
|
#select(&block) ⇒ Object
1521
1522
1523
1524
1525
1526
|
# File 'lib/RMagick.rb', line 1521
def select(&block)
cfid = self[@scene].__id__ rescue nil
a = self.class.new.replace super
a.set_cf cfid
return a
end
|
#shift ⇒ Object
1528
1529
1530
1531
1532
1533
|
# File 'lib/RMagick.rb', line 1528
def shift
cfid = self[@scene].__id__ rescue nil
a = super
set_cf cfid
return a
end
|
#slice(*args) ⇒ Object
1535
1536
1537
|
# File 'lib/RMagick.rb', line 1535
def slice(*args)
self[*args]
end
|
#slice!(*args) ⇒ Object
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
|
# File 'lib/RMagick.rb', line 1539
def slice!(*args)
cfid = self[@scene].__id__ rescue nil
if args.length > 1 || args[0].kind_of?(Range)
a = self.class.new.replace super
else
a = super
end
set_cf cfid
return a
end
|
#ticks_per_second=(t) ⇒ Object
1629
1630
1631
1632
1633
1634
|
# File 'lib/RMagick.rb', line 1629
def ticks_per_second=(t)
if Integer(t) < 0
Kernel.raise ArgumentError, "ticks_per_second must be greater than or equal to 0"
end
each { |f| f.ticks_per_second = Integer(t) }
end
|
#to_blob ⇒ Object
#uniq ⇒ Object
1550
1551
1552
1553
1554
1555
|
# File 'lib/RMagick.rb', line 1550
def uniq
cfid = self[@scene].__id__ rescue nil
a = self.class.new.replace super
a.set_cf cfid
return a
end
|
#uniq!(*args) ⇒ Object
1557
1558
1559
1560
1561
1562
|
# File 'lib/RMagick.rb', line 1557
def uniq!(*args)
cfid = self[@scene].__id__ rescue nil
a = super
set_cf cfid
return a
end
|
#unshift(obj) ⇒ Object
1565
1566
1567
1568
1569
1570
|
# File 'lib/RMagick.rb', line 1565
def unshift(obj)
is_a_image obj
a = super
@scene = 0
return a
end
|
#write ⇒ Object
#|(other) ⇒ Object
1342
1343
1344
1345
1346
1347
1348
|
# File 'lib/RMagick.rb', line 1342
def |(other)
is_a_image_array other
cfid = self[@scene].__id__ rescue nil
a = self.class.new.replace super
a.set_cf cfid
return a
end
|