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
-
#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
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
|
# File 'lib/RMagick.rb', line 1519
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.
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
|
# File 'lib/RMagick.rb', line 1551
def method_missing(methID, *args, &block)
begin
if @scene
self[@scene].send(methID, *args, &block)
else
super
end
rescue NoMethodError
raise NoMethodError, "undefined method `#{methID.id2name}' for #{self.class}"
rescue Exception
$@.delete_if { |s| /:in `send'$/.match(s) || /:in `method_missing'$/.match(s) }
raise
end
end
|
Instance Attribute Details
#scene ⇒ Object
Returns the value of attribute scene.
1073
1074
1075
|
# File 'lib/RMagick.rb', line 1073
def scene
@scene
end
|
Instance Method Details
#&(other) ⇒ Object
1165
1166
1167
1168
1169
1170
1171
|
# File 'lib/RMagick.rb', line 1165
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
1173
1174
1175
1176
1177
1178
1179
1180
1181
|
# File 'lib/RMagick.rb', line 1173
def *(n)
unless n.kind_of? Integer
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
1183
1184
1185
1186
1187
1188
|
# File 'lib/RMagick.rb', line 1183
def +(other)
cfid = self[@scene].__id__ rescue nil
a = self.class.new.replace super
a.set_cf cfid
return a
end
|
#-(other) ⇒ Object
1190
1191
1192
1193
1194
1195
1196
|
# File 'lib/RMagick.rb', line 1190
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
1198
1199
1200
1201
1202
1203
|
# File 'lib/RMagick.rb', line 1198
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
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
|
# File 'lib/RMagick.rb', line 1440
def <=>(other)
unless other.kind_of? self.class
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?
raise TypeError, "cannot convert nil into #{other.scene.class}"
elsif ! @scene.nil? && other.scene.nil?
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
1134
1135
1136
1137
1138
1139
1140
|
# File 'lib/RMagick.rb', line 1134
def [](*args)
if (args.length > 1) || args[0].kind_of?(Range)
self.class.new.replace super
else
super
end
end
|
#[]=(*args) ⇒ Object
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
|
# File 'lib/RMagick.rb', line 1142
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.
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
|
# File 'lib/RMagick.rb', line 1305
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
1567
|
# File 'lib/RMagick.rb', line 1567
alias_method :__respond_to__?, :respond_to?
|
#animate ⇒ Object
#append ⇒ Object
#average ⇒ Object
#clear ⇒ Object
1213
1214
1215
1216
|
# File 'lib/RMagick.rb', line 1213
def clear
@scene = nil
super
end
|
#clone ⇒ Object
1461
1462
1463
1464
1465
|
# File 'lib/RMagick.rb', line 1461
def clone
ditto = dup
ditto.freeze if frozen?
return ditto
end
|
#coalesce ⇒ Object
#collect(&block) ⇒ Object
1218
1219
1220
1221
1222
1223
|
# File 'lib/RMagick.rb', line 1218
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
1225
1226
1227
1228
1229
|
# File 'lib/RMagick.rb', line 1225
def collect!(&block)
super
is_a_image_array self
self
end
|
#compact ⇒ Object
1231
1232
1233
1234
1235
1236
|
# File 'lib/RMagick.rb', line 1231
def compact
cfid = self[@scene].__id__ rescue nil
a = self.class.new.replace super
a.set_cf cfid
return a
end
|
#compact! ⇒ Object
1238
1239
1240
1241
1242
1243
|
# File 'lib/RMagick.rb', line 1238
def compact!
cfid = self[@scene].__id__ rescue nil
a = super set_cf cfid
return a
end
|
#concat(other) ⇒ Object
1245
1246
1247
1248
1249
1250
|
# File 'lib/RMagick.rb', line 1245
def concat(other)
is_a_image_array other
a = super
@scene = length-1
return a
end
|
#copy ⇒ Object
1468
1469
1470
1471
1472
1473
1474
|
# File 'lib/RMagick.rb', line 1468
def copy
ditto = self.class.new
each { |f| ditto << f.copy }
ditto.scene = @scene
ditto.taint if tainted?
return ditto
end
|
#cur_image ⇒ Object
1477
1478
1479
1480
1481
1482
|
# File 'lib/RMagick.rb', line 1477
def cur_image
if ! @scene
raise IndexError, "no images in this list"
end
self[@scene]
end
|
#deconstruct ⇒ Object
#delay=(d) ⇒ Object
Set same delay for all images
1485
1486
1487
1488
1489
1490
|
# File 'lib/RMagick.rb', line 1485
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
1252
1253
1254
1255
1256
1257
1258
|
# File 'lib/RMagick.rb', line 1252
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
1260
1261
1262
1263
1264
1265
|
# File 'lib/RMagick.rb', line 1260
def delete_at(ndx)
cfid = self[@scene].__id__ rescue nil
a = super
set_cf cfid
return a
end
|
#delete_if(&block) ⇒ Object
1267
1268
1269
1270
1271
1272
|
# File 'lib/RMagick.rb', line 1267
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
1499
1500
1501
1502
1503
1504
1505
|
# File 'lib/RMagick.rb', line 1499
def dup
ditto = self.class.new
each {|img| ditto << img}
ditto.scene = @scene
ditto.taint if tainted?
return ditto
end
|
#fill(*args, &block) ⇒ Object
1274
1275
1276
1277
1278
1279
1280
1281
|
# File 'lib/RMagick.rb', line 1274
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
1283
1284
1285
1286
1287
1288
|
# File 'lib/RMagick.rb', line 1283
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
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
|
# File 'lib/RMagick.rb', line 1507
def from_blob(*blobs, &block)
if (blobs.length == 0)
raise ArgumentError, "no blobs given"
end
blobs.each { |b|
Magick::Image.from_blob(b, &block).each { |n| self << n }
}
@scene = length - 1
self
end
|
#insert(*args) ⇒ Object
1291
1292
1293
1294
1295
1296
1297
1298
|
# File 'lib/RMagick.rb', line 1291
def insert(*args)
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
1531
1532
1533
1534
1535
|
# File 'lib/RMagick.rb', line 1531
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
1538
1539
1540
1541
1542
1543
1544
1545
|
# File 'lib/RMagick.rb', line 1538
def iterations=(n)
n = Integer(n)
if n < 0 || n > 65535
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
1317
1318
1319
1320
1321
1322
1323
1324
|
# File 'lib/RMagick.rb', line 1317
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
1578
1579
1580
|
# File 'lib/RMagick.rb', line 1578
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
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
|
# File 'lib/RMagick.rb', line 1583
def ping(*files, &block)
if (files.length == 0)
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
1326
1327
1328
1329
1330
1331
|
# File 'lib/RMagick.rb', line 1326
def pop
cfid = self[@scene].__id__ rescue nil
a = super set_cf cfid
return a
end
|
#push(*objs) ⇒ Object
1333
1334
1335
1336
1337
1338
|
# File 'lib/RMagick.rb', line 1333
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
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
|
# File 'lib/RMagick.rb', line 1595
def read(*files, &block)
if (files.length == 0)
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
1340
1341
1342
1343
1344
1345
|
# File 'lib/RMagick.rb', line 1340
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
1347
1348
1349
1350
1351
1352
|
# File 'lib/RMagick.rb', line 1347
def reject!(&block)
cfid = self[@scene].__id__ rescue nil
a = super set_cf cfid
return a
end
|
#replace(other) ⇒ Object
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
|
# File 'lib/RMagick.rb', line 1354
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
1568
1569
1570
1571
1572
1573
1574
1575
|
# File 'lib/RMagick.rb', line 1568
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
1370
1371
1372
1373
1374
1375
|
# File 'lib/RMagick.rb', line 1370
def reverse
cfid = self[@scene].__id__ rescue nil
a = self.class.new.replace super
a.set_cf cfid
return a
end
|
#reverse! ⇒ Object
1377
1378
1379
1380
1381
1382
|
# File 'lib/RMagick.rb', line 1377
def reverse!
cfid = self[@scene].__id__ rescue nil
a = super
set_cf cfid
return a
end
|
#select(&block) ⇒ Object
1384
1385
1386
1387
1388
1389
|
# File 'lib/RMagick.rb', line 1384
def select(&block)
cfid = self[@scene].__id__ rescue nil
a = self.class.new.replace super
a.set_cf cfid
return a
end
|
#shift ⇒ Object
1391
1392
1393
1394
1395
1396
|
# File 'lib/RMagick.rb', line 1391
def shift
cfid = self[@scene].__id__ rescue nil
a = super
set_cf cfid
return a
end
|
#slice(*args) ⇒ Object
1398
1399
1400
|
# File 'lib/RMagick.rb', line 1398
def slice(*args)
self[*args]
end
|
#slice!(*args) ⇒ Object
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
|
# File 'lib/RMagick.rb', line 1402
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
1492
1493
1494
1495
1496
1497
|
# File 'lib/RMagick.rb', line 1492
def ticks_per_second=(t)
if Integer(t) < 0
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
1413
1414
1415
1416
1417
1418
|
# File 'lib/RMagick.rb', line 1413
def uniq
cfid = self[@scene].__id__ rescue nil
a = self.class.new.replace super
a.set_cf cfid
return a
end
|
#uniq!(*args) ⇒ Object
1420
1421
1422
1423
1424
1425
|
# File 'lib/RMagick.rb', line 1420
def uniq!(*args)
cfid = self[@scene].__id__ rescue nil
a = super
set_cf cfid
return a
end
|
#unshift(obj) ⇒ Object
1428
1429
1430
1431
1432
1433
|
# File 'lib/RMagick.rb', line 1428
def unshift(obj)
is_a_image obj
a = super
@scene = 0
return a
end
|
#write ⇒ Object
#|(other) ⇒ Object
1205
1206
1207
1208
1209
1210
1211
|
# File 'lib/RMagick.rb', line 1205
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
|