Class: Magick::ImageList
- Inherits:
-
Array
- Object
- Array
- Magick::ImageList
show all
- Includes:
- Comparable, Enumerable
- Defined in:
- lib/RMagick.rb,
lib/rmagick4j/image_list.rb
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#*(n) ⇒ 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
-
#__respond_to__? ⇒ Object
Ensure respond_to? answers correctly when we are delegating to Image.
-
#affinity ⇒ Object
ImageMagic used affinity in 6.4.3, switch to remap in 6.4.4.
-
#clear ⇒ Object
-
#clone ⇒ Object
-
#collect(&block) ⇒ Object
(also: #__map__)
override Enumerable#collect.
-
#collect!(&block) ⇒ Object
(also: #map!, #__map__!)
-
#compact ⇒ Object
-
#compact! ⇒ Object
-
#concat(other) ⇒ Object
-
#copy ⇒ Object
-
#cur_image ⇒ Object
Return the current image.
-
#delay=(d) ⇒ Object
Set same delay for all images.
-
#delete(obj, &block) ⇒ Object
-
#delete_at(ndx) ⇒ Object
-
#delete_if(&block) ⇒ Object
-
#dup ⇒ Object
-
#eql?(other) ⇒ Boolean
-
#fill(*args, &block) ⇒ Object
-
#find_all(&block) ⇒ Object
(also: #select)
Override Enumerable’s find_all.
-
#flatten_images ⇒ Object
-
#from_blob(*blobs, &block) ⇒ Object
-
#initialize(*filenames, &block) ⇒ ImageList
constructor
Initialize new instances.
-
#insert(index, *args) ⇒ Object
-
#inspect ⇒ Object
Call inspect for all the images.
-
#iterations=(n) ⇒ Object
Set the number of iterations of an animated GIF.
-
#last(*args) ⇒ Object
-
#marshal_dump ⇒ Object
Custom marshal/unmarshal for Ruby 1.8.
-
#marshal_load(ary) ⇒ 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.
-
#new_image(cols, rows, *fill, &info_blk) ⇒ Object
Create a new image and add it to the end.
-
#nitems ⇒ Object
-
#partition(&block) ⇒ Object
-
#ping(*files, &block) ⇒ Object
Ping files and concatenate the new images.
-
#pop ⇒ Object
-
#push(*objs) ⇒ Object
-
#read(*files, &block) ⇒ Object
Read files and concatenate the new images.
-
#reject(&block) ⇒ Object
override Enumerable’s reject.
-
#reject!(&block) ⇒ Object
-
#remap ⇒ Object
-
#replace(other) ⇒ Object
-
#respond_to?(methID, priv = false) ⇒ Boolean
-
#reverse ⇒ Object
-
#reverse! ⇒ Object
-
#reverse_each ⇒ Object
-
#shift ⇒ Object
-
#slice(*args) ⇒ Object
-
#slice!(*args) ⇒ Object
-
#ticks_per_second=(t) ⇒ Object
-
#to_a ⇒ Object
-
#to_blob(&add) ⇒ Object
-
#uniq ⇒ Object
-
#uniq!(*args) ⇒ Object
-
#unshift(obj) ⇒ Object
-
#values_at(*args) ⇒ Object
(also: #indexes, #indices)
Constructor Details
#initialize(*filenames, &block) ⇒ ImageList
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
|
# File 'lib/RMagick.rb', line 1610
def initialize(*filenames, &block)
@images = []
@scene = nil
filenames.each { |f|
Magick::Image.read(f, &block).each { |n| @images << 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.
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
|
# File 'lib/RMagick.rb', line 1677
def method_missing(methID, *args, &block)
begin
if @scene
@images[@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.
1277
1278
1279
|
# File 'lib/RMagick.rb', line 1277
def scene
@scene
end
|
Instance Method Details
#*(n) ⇒ Object
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
|
# File 'lib/RMagick.rb', line 1369
def *(n)
unless n.kind_of? Integer
Kernel.raise ArgumentError, "Integer required (#{n.class} given)"
end
current = get_current()
ilist = self.class.new
(@images * n).each {|image| ilist << image}
ilist.set_current current
return ilist
end
|
#<<(obj) ⇒ Object
1380
1381
1382
1383
1384
1385
|
# File 'lib/RMagick.rb', line 1380
def <<(obj)
is_an_image obj
@images << obj
@scene = @images.length - 1
self
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
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
|
# File 'lib/RMagick.rb', line 1392
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
1413
1414
1415
1416
1417
1418
1419
1420
1421
|
# File 'lib/RMagick.rb', line 1413
def [](*args)
a = @images[*args]
if a.respond_to?(:each) then
ilist = self.class.new
a.each {|image| ilist << image}
a = ilist
end
return a
end
|
#[]=(*args) ⇒ Object
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
|
# File 'lib/RMagick.rb', line 1423
def []=(*args)
obj = @images.[]=(*args)
if obj && obj.respond_to?(:each) then
is_an_image_array(obj)
set_current obj.last.__id__
elsif obj
is_an_image(obj)
set_current obj.__id__
else
set_current nil
end
return obj
end
|
#__respond_to__? ⇒ Object
Ensure respond_to? answers correctly when we are delegating to Image
1777
|
# File 'lib/RMagick.rb', line 1777
alias_method :__respond_to__?, :respond_to?
|
#affinity ⇒ Object
ImageMagic used affinity in 6.4.3, switch to remap in 6.4.4.
1504
|
# File 'lib/RMagick.rb', line 1504
alias_method :affinity, :remap
|
#clear ⇒ Object
1454
1455
1456
1457
|
# File 'lib/RMagick.rb', line 1454
def clear
@scene = nil
@images.clear
end
|
#clone ⇒ Object
1459
1460
1461
1462
1463
|
# File 'lib/RMagick.rb', line 1459
def clone
ditto = dup
ditto.freeze if frozen?
return ditto
end
|
#collect(&block) ⇒ Object
Also known as:
__map__
override Enumerable#collect
1466
1467
1468
1469
1470
1471
1472
1473
|
# File 'lib/RMagick.rb', line 1466
def collect(&block)
current = get_current()
a = @images.collect(&block)
ilist = self.class.new
a.each {|image| ilist << image}
ilist.set_current current
return ilist
end
|
#collect!(&block) ⇒ Object
Also known as:
map!, __map__!
1475
1476
1477
1478
1479
|
# File 'lib/RMagick.rb', line 1475
def collect!(&block)
@images.collect!(&block)
is_an_image_array @images
self
end
|
#compact ⇒ Object
1506
1507
1508
1509
1510
1511
1512
1513
|
# File 'lib/RMagick.rb', line 1506
def compact
current = get_current()
ilist = self.class.new
a = @images.compact
a.each {|image| ilist << image}
ilist.set_current current
return ilist
end
|
#compact! ⇒ Object
1515
1516
1517
1518
1519
1520
|
# File 'lib/RMagick.rb', line 1515
def compact!
current = get_current()
a = @images.compact! set_current current
return a.nil? ? nil : self
end
|
#concat(other) ⇒ Object
1522
1523
1524
1525
1526
1527
|
# File 'lib/RMagick.rb', line 1522
def concat(other)
is_an_image_array other
other.each {|image| @images << image}
@scene = length-1
return self
end
|
#copy ⇒ Object
1482
1483
1484
1485
1486
1487
1488
|
# File 'lib/RMagick.rb', line 1482
def copy
ditto = self.class.new
@images.each { |f| ditto << f.copy }
ditto.scene = @scene
ditto.taint if tainted?
return ditto
end
|
#cur_image ⇒ Object
1491
1492
1493
1494
1495
1496
|
# File 'lib/RMagick.rb', line 1491
def cur_image
if ! @scene
Kernel.raise IndexError, "no images in this list"
end
@images[@scene]
end
|
#delay=(d) ⇒ Object
Set same delay for all images
1530
1531
1532
1533
1534
1535
|
# File 'lib/RMagick.rb', line 1530
def delay=(d)
if Integer(d) < 0
raise ArgumentError, "delay must be greater than or equal to 0"
end
@images.each { |f| f.delay = Integer(d) }
end
|
#delete(obj, &block) ⇒ Object
1537
1538
1539
1540
1541
1542
1543
|
# File 'lib/RMagick.rb', line 1537
def delete(obj, &block)
is_an_image obj
current = get_current()
a = @images.delete(obj, &block)
set_current current
return a
end
|
#delete_at(ndx) ⇒ Object
1545
1546
1547
1548
1549
1550
|
# File 'lib/RMagick.rb', line 1545
def delete_at(ndx)
current = get_current()
a = @images.delete_at(ndx)
set_current current
return a
end
|
#delete_if(&block) ⇒ Object
1552
1553
1554
1555
1556
1557
|
# File 'lib/RMagick.rb', line 1552
def delete_if(&block)
current = get_current()
@images.delete_if(&block)
set_current current
self
end
|
#dup ⇒ Object
1559
1560
1561
1562
1563
1564
1565
|
# File 'lib/RMagick.rb', line 1559
def dup
ditto = self.class.new
@images.each {|img| ditto << img}
ditto.scene = @scene
ditto.taint if tainted?
return ditto
end
|
#eql?(other) ⇒ Boolean
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
|
# File 'lib/RMagick.rb', line 1567
def eql?(other)
is_an_image_array other
eql = other.eql?(@images)
begin eql &&= @scene == other.scene
rescue NoMethodError
end
return eql
end
|
#fill(*args, &block) ⇒ Object
1578
1579
1580
1581
1582
1583
1584
1585
|
# File 'lib/RMagick.rb', line 1578
def fill(*args, &block)
is_an_image args[0] unless block_given?
current = get_current()
@images.fill(*args, &block)
is_an_image_array self
set_current current
self
end
|
#find_all(&block) ⇒ Object
Also known as:
select
Override Enumerable’s find_all
1588
1589
1590
1591
1592
1593
1594
1595
|
# File 'lib/RMagick.rb', line 1588
def find_all(&block)
current = get_current()
a = @images.find_all(&block)
ilist = self.class.new
a.each {|image| ilist << image}
ilist.set_current current
return ilist
end
|
#flatten_images ⇒ Object
6
7
8
9
10
11
12
13
14
|
# File 'lib/rmagick4j/image_list.rb', line 6
def flatten_images
img = @images.map { |obj| obj._image }
image = img.inject do |memo, obj|
memo.flatten(obj)
end
Image.from_image(image)
end
|
#from_blob(*blobs, &block) ⇒ Object
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
|
# File 'lib/RMagick.rb', line 1598
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| @images << n }
}
@scene = length - 1
self
end
|
#insert(index, *args) ⇒ Object
1622
1623
1624
1625
1626
1627
1628
|
# File 'lib/RMagick.rb', line 1622
def insert(index, *args)
args.each {|image| is_an_image image}
current = get_current()
@images.insert(index, *args)
set_current current
return self
end
|
#inspect ⇒ Object
Call inspect for all the images
1631
1632
1633
1634
1635
|
# File 'lib/RMagick.rb', line 1631
def inspect
img = []
@images.each {|image| img << image.inspect }
img = "[" + img.join(",\n") + "]\nscene=#{@scene}"
end
|
#iterations=(n) ⇒ Object
Set the number of iterations of an animated GIF
1638
1639
1640
1641
1642
1643
1644
1645
|
# File 'lib/RMagick.rb', line 1638
def iterations=(n)
n = Integer(n)
if n < 0 || n > 65535
Kernel.raise ArgumentError, "iterations must be between 0 and 65535"
end
@images.each {|f| f.iterations=n}
self
end
|
#last(*args) ⇒ Object
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
|
# File 'lib/RMagick.rb', line 1647
def last(*args)
if args.length == 0
a = @images.last
else
a = @images.last(*args)
ilist = self.class.new
a.each {|img| ilist << img}
@scene = a.length - 1
a = ilist
end
return a
end
|
#marshal_dump ⇒ Object
Custom marshal/unmarshal for Ruby 1.8.
1661
1662
1663
1664
1665
|
# File 'lib/RMagick.rb', line 1661
def marshal_dump()
ary = [@scene]
@images.each {|i| ary << Marshal.dump(i)}
ary
end
|
#marshal_load(ary) ⇒ Object
1667
1668
1669
1670
1671
|
# File 'lib/RMagick.rb', line 1667
def marshal_load(ary)
@scene = ary.shift
@images = []
ary.each {|a| @images << Marshal.load(a)}
end
|
#new_image(cols, rows, *fill, &info_blk) ⇒ Object
Create a new image and add it to the end
1693
1694
1695
|
# File 'lib/RMagick.rb', line 1693
def new_image(cols, rows, *fill, &info_blk)
self << Magick::Image.new(cols, rows, *fill, &info_blk)
end
|
#nitems ⇒ Object
1449
1450
1451
|
# File 'lib/RMagick.rb', line 1449
def nitems()
@images.nitems()
end
|
#partition(&block) ⇒ Object
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
|
# File 'lib/RMagick.rb', line 1697
def partition(&block)
a = @images.partition(&block)
t = self.class.new
a[0].each { |img| t << img}
t.set_current nil
f = self.class.new
a[1].each { |img| f << img}
f.set_current nil
[t, f]
end
|
#ping(*files, &block) ⇒ Object
Ping files and concatenate the new images
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
|
# File 'lib/RMagick.rb', line 1709
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| @images << n }
}
@scene = length - 1
self
end
|
#pop ⇒ Object
1720
1721
1722
1723
1724
1725
|
# File 'lib/RMagick.rb', line 1720
def pop
current = get_current()
a = @images.pop set_current current
return a
end
|
#push(*objs) ⇒ Object
1727
1728
1729
1730
1731
1732
1733
1734
|
# File 'lib/RMagick.rb', line 1727
def push(*objs)
objs.each do |image|
is_an_image image
@images << image
end
@scene = length - 1
self
end
|
#read(*files, &block) ⇒ Object
Read files and concatenate the new images
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
|
# File 'lib/RMagick.rb', line 1737
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| @images << n }
}
@scene = length - 1
self
end
|
#reject(&block) ⇒ Object
override Enumerable’s reject
1749
1750
1751
1752
1753
1754
1755
1756
|
# File 'lib/RMagick.rb', line 1749
def reject(&block)
current = get_current()
ilist = self.class.new
a = @images.reject(&block)
a.each {|image| ilist << image}
ilist.set_current current
return ilist
end
|
#reject!(&block) ⇒ Object
1758
1759
1760
1761
1762
1763
1764
|
# File 'lib/RMagick.rb', line 1758
def reject!(&block)
current = get_current()
a = @images.reject!(&block)
@images = a if !a.nil?
set_current current
return a.nil? ? nil : self
end
|
#remap ⇒ Object
16
17
18
|
# File 'lib/rmagick4j/image_list.rb', line 16
def remap
end
|
#replace(other) ⇒ Object
1766
1767
1768
1769
1770
1771
1772
1773
1774
|
# File 'lib/RMagick.rb', line 1766
def replace(other)
is_an_image_array other
current = get_current()
@images.clear
other.each {|image| @images << image}
@scene = self.length == 0 ? nil : 0
set_current current
self
end
|
#respond_to?(methID, priv = false) ⇒ Boolean
1778
1779
1780
1781
1782
1783
1784
1785
|
# File 'lib/RMagick.rb', line 1778
def respond_to?(methID, priv=false)
return true if __respond_to__?(methID, priv)
if @scene
@images[@scene].respond_to?(methID, priv)
else
super
end
end
|
#reverse ⇒ Object
1787
1788
1789
1790
1791
1792
1793
|
# File 'lib/RMagick.rb', line 1787
def reverse
current = get_current()
a = self.class.new
@images.reverse_each {|image| a << image}
a.set_current current
return a
end
|
#reverse! ⇒ Object
1795
1796
1797
1798
1799
1800
|
# File 'lib/RMagick.rb', line 1795
def reverse!
current = get_current()
@images.reverse!
set_current current
self
end
|
#reverse_each ⇒ Object
1802
1803
1804
1805
|
# File 'lib/RMagick.rb', line 1802
def reverse_each
@images.reverse_each {|image| yield(image)}
self
end
|
#shift ⇒ Object
1807
1808
1809
1810
1811
1812
|
# File 'lib/RMagick.rb', line 1807
def shift
current = get_current()
a = @images.shift
set_current current
return a
end
|
#slice(*args) ⇒ Object
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
|
# File 'lib/RMagick.rb', line 1814
def slice(*args)
current = get_current()
slice = @images.slice(*args)
if slice
ilist = self.class.new
if slice.respond_to?(:each) then
slice.each {|image| ilist << image}
else
ilist << slice
end
else
ilist = nil
end
return ilist
end
|
#slice!(*args) ⇒ Object
1830
1831
1832
1833
1834
1835
|
# File 'lib/RMagick.rb', line 1830
def slice!(*args)
current = get_current()
a = @images.slice!(*args)
set_current current
return a
end
|
#ticks_per_second=(t) ⇒ Object
1837
1838
1839
1840
1841
1842
|
# File 'lib/RMagick.rb', line 1837
def ticks_per_second=(t)
if Integer(t) < 0
Kernel.raise ArgumentError, "ticks_per_second must be greater than or equal to 0"
end
@images.each { |f| f.ticks_per_second = Integer(t) }
end
|
#to_a ⇒ Object
1844
1845
1846
1847
1848
|
# File 'lib/RMagick.rb', line 1844
def to_a
a = Array.new
@images.each {|image| a << image}
return a
end
|
#to_blob(&add) ⇒ Object
20
21
22
23
|
# File 'lib/rmagick4j/image_list.rb', line 20
def to_blob(&add)
first.to_blob(&add)
end
|
#uniq ⇒ Object
1850
1851
1852
1853
1854
1855
1856
|
# File 'lib/RMagick.rb', line 1850
def uniq
current = get_current()
a = self.class.new
@images.uniq.each {|image| a << image}
a.set_current current
return a
end
|
#uniq!(*args) ⇒ Object
1858
1859
1860
1861
1862
1863
|
# File 'lib/RMagick.rb', line 1858
def uniq!(*args)
current = get_current()
a = @images.uniq!
set_current current
return a.nil? ? nil : self
end
|
#unshift(obj) ⇒ Object
1866
1867
1868
1869
1870
1871
|
# File 'lib/RMagick.rb', line 1866
def unshift(obj)
is_an_image obj
@images.unshift(obj)
@scene = 0
self
end
|
#values_at(*args) ⇒ Object
Also known as:
indexes, indices
1873
1874
1875
1876
1877
1878
1879
|
# File 'lib/RMagick.rb', line 1873
def values_at(*args)
a = @images.values_at(*args)
a = self.class.new
@images.values_at(*args).each {|image| a << image}
a.scene = a.length - 1
return a
end
|