Class: Magick::ImageList
- Inherits:
-
Object
- Object
- Magick::ImageList
- Includes:
- Comparable, Enumerable
- Defined in:
- lib/rmagick_internal.rb,
ext/RMagick/rmmain.c
Overview
class Magick::Image
Defined Under Namespace
Classes: Montage
Instance Attribute Summary collapse
-
#scene ⇒ Object
Returns the value of attribute scene.
Instance Method Summary collapse
- #*(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
-
#__respond_to__? ⇒ Object
Ensure respond_to? answers correctly when we are delegating to Image.
-
#animate(*args) ⇒ Object
Repeatedly display the images in the images array to an XWindow screen.
-
#append(stack_arg) ⇒ Object
Append all the images by calling ImageAppend.
-
#average ⇒ Object
Average all images together by calling AverageImages.
- #clear ⇒ Object
- #clone ⇒ Object
-
#coalesce ⇒ Object
Call CoalesceImages.
-
#collect(&block) ⇒ Object
(also: #__map__)
override Enumerable#collect.
- #collect!(&block) ⇒ Object (also: #map!, #__map__!)
-
#combine(*args) ⇒ Object
Combines the images using the specified colorspace.
- #compact ⇒ Object
- #compact! ⇒ Object
-
#composite_layers(*args) ⇒ Object
Equivalent to convert’s -layers composite option.
- #concat(other) ⇒ Object
-
#copy ⇒ Object
Make a deep copy.
-
#cur_image ⇒ Object
Return the current image.
-
#deconstruct ⇒ Object
Compare each image with the next in a sequence and returns the maximum bounding region of any pixel differences it discovers.
-
#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__)
Display all the images to an X window screen.
- #dup ⇒ Object
- #eql?(other) ⇒ Boolean
- #fill(*args, &block) ⇒ Object
-
#find_all(&block) ⇒ Object
(also: #select)
Override Enumerable’s find_all.
-
#flatten_images ⇒ Object
Merge all the images into a single image.
- #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(meth_id, *args, &block) ⇒ Object
The ImageList class supports the Magick::Image class methods by simply sending the method to the current image.
-
#montage ⇒ Object
Call MontageImages.
-
#morph(nimages) ⇒ Object
Requires a minimum of two images.
-
#mosaic ⇒ Object
Merge all the images into a single image.
-
#new_image(cols, rows, *fill, &info_blk) ⇒ Object
Create a new image and add it to the end.
-
#optimize_layers(method) ⇒ Object
Equivalent to -layers option in ImageMagick 6.2.6.
- #partition(&block) ⇒ Object
-
#ping(*files, &block) ⇒ Object
Ping files and concatenate the new images.
- #pop ⇒ Object
- #push(*objs) ⇒ Object
-
#quantize(*args) ⇒ Object
Call QuantizeImages.
-
#read(*files, &block) ⇒ Object
Read files and concatenate the new images.
-
#reject(&block) ⇒ Object
override Enumerable’s reject.
- #reject!(&block) ⇒ Object
-
#remap(*args) ⇒ Object
(also: #affinity)
Call RemapImages.
- #replace(other) ⇒ Object
- #respond_to?(meth_id, 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 ⇒ Object
Return the imagelist as a blob (a String).
- #uniq ⇒ Object
- #uniq!(*_args) ⇒ Object
- #unshift(obj) ⇒ Object
- #values_at(*args) ⇒ Object (also: #indexes, #indices)
-
#write(file) ⇒ Object
Write all the images to the specified file.
Constructor Details
#initialize(*filenames, &block) ⇒ ImageList
Initialize new instances
1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 |
# File 'lib/rmagick_internal.rb', line 1541 def initialize(*filenames, &block) @images = [] @scene = nil filenames.each do |f| Magick::Image.read(f, &block).each { |n| @images << n } end if length > 0 @scene = length - 1 # last image in array end self end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth_id, *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.
1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 |
# File 'lib/rmagick_internal.rb', line 1606 def method_missing(meth_id, *args, &block) if @scene @images[@scene].send(meth_id, *args, &block) else super end rescue NoMethodError Kernel.raise NoMethodError, "undefined method `#{meth_id.id2name}' for #{self.class}" rescue Exception $ERROR_POSITION.delete_if { |s| /:in `send'$/.match(s) || /:in `method_missing'$/.match(s) } Kernel.raise end |
Instance Attribute Details
#scene ⇒ Object
Returns the value of attribute scene.
1232 1233 1234 |
# File 'lib/rmagick_internal.rb', line 1232 def scene @scene end |
Instance Method Details
#*(other) ⇒ Object
1318 1319 1320 1321 1322 1323 1324 1325 |
# File 'lib/rmagick_internal.rb', line 1318 def *(other) Kernel.raise ArgumentError, "Integer required (#{other.class} given)" unless other.is_a? Integer current = get_current ilist = self.class.new (@images * other).each { |image| ilist << image } ilist.set_current current ilist end |
#<<(obj) ⇒ Object
1327 1328 1329 1330 1331 1332 |
# File 'lib/rmagick_internal.rb', line 1327 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
1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 |
# File 'lib/rmagick_internal.rb', line 1339 def <=>(other) Kernel.raise TypeError, "#{self.class} required (#{other.class} given)" unless other.is_a? self.class size = [length, other.length].min size.times do |x| r = self[x] <=> other[x] return r unless r.zero? end return 0 if @scene.nil? && other.scene.nil? Kernel.raise TypeError, "cannot convert nil into #{other.scene.class}" if @scene.nil? && !other.scene.nil? Kernel.raise TypeError, "cannot convert nil into #{scene.class}" if !@scene.nil? && other.scene.nil? r = scene <=> other.scene return r unless r.zero? length <=> other.length end |
#[](*args) ⇒ Object
1356 1357 1358 1359 1360 1361 1362 1363 1364 |
# File 'lib/rmagick_internal.rb', line 1356 def [](*args) a = @images[*args] if a.respond_to?(:each) ilist = self.class.new a.each { |image| ilist << image } a = ilist end a end |
#[]=(*args) ⇒ Object
1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 |
# File 'lib/rmagick_internal.rb', line 1366 def []=(*args) obj = @images.[]=(*args) if obj && obj.respond_to?(:each) 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 obj end |
#__respond_to__? ⇒ Object
Ensure respond_to? answers correctly when we are delegating to Image
1700 |
# File 'lib/rmagick_internal.rb', line 1700 alias __respond_to__? respond_to? |
#animate(*args) ⇒ Object
Repeatedly display the images in the images array to an XWindow screen. The “delay” argument is the number of 1/100ths of a second (0 to 65535) to delay between images.
Ruby usage:
- @verbatim ImageList#animate @endverbatim
- @verbatim ImageList#animate(delay) @endverbatim
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'ext/RMagick/rmilist.c', line 42
VALUE
ImageList_animate(int argc, VALUE *argv, VALUE self)
{
Image *images;
Info *info;
VALUE info_obj;
unsigned int delay;
if (argc == 1)
{
delay = NUM2UINT(argv[0]);
}
if (argc > 1)
{
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
}
// Create a new Info object to use with this call
info_obj = rm_info_new();
// Convert the images array to an images sequence.
images = images_from_imagelist(self);
if (argc == 1)
{
Image *img;
for (img = images; img; img = GetNextImageInList(img))
{
img->delay = delay;
}
}
Data_Get_Struct(info_obj, Info, info);
(void) AnimateImages(info, images);
rm_check_image_exception(images, RetainOnError);
rm_split(images);
RB_GC_GUARD(info_obj);
return self;
}
|
#append(stack_arg) ⇒ Object
Append all the images by calling ImageAppend.
Ruby usage:
- @verbatim ImageList#append(stack) @endverbatim
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'ext/RMagick/rmilist.c', line 96
VALUE
ImageList_append(VALUE self, VALUE stack_arg)
{
Image *images, *new_image;
unsigned int stack;
ExceptionInfo *exception;
// Convert the image array to an image sequence.
images = images_from_imagelist(self);
// If stack == true, stack rectangular images top-to-bottom,
// otherwise left-to-right.
stack = RTEST(stack_arg);
exception = AcquireExceptionInfo();
new_image = AppendImages(images, stack, exception);
rm_split(images);
rm_check_exception(exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#average ⇒ Object
Average all images together by calling AverageImages.
Ruby usage:
- @verbatim ImageList#average @endverbatim
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'ext/RMagick/rmilist.c', line 131
VALUE
ImageList_average(VALUE self)
{
Image *images, *new_image;
ExceptionInfo *exception;
// Convert the images array to an images sequence.
images = images_from_imagelist(self);
exception = AcquireExceptionInfo();
new_image = EvaluateImages(images, MeanEvaluateOperator, exception);
rm_split(images);
rm_check_exception(exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#clear ⇒ Object
1390 1391 1392 1393 |
# File 'lib/rmagick_internal.rb', line 1390 def clear @scene = nil @images.clear end |
#clone ⇒ Object
1395 1396 1397 1398 1399 |
# File 'lib/rmagick_internal.rb', line 1395 def clone ditto = dup ditto.freeze if frozen? ditto end |
#coalesce ⇒ Object
Call CoalesceImages.
Ruby usage:
- @verbatim ImageList#coalesce @endverbatim
Notes:
- Respects the delay, matte, and start_loop fields in each image.
images array
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'ext/RMagick/rmilist.c', line 166
VALUE
ImageList_coalesce(VALUE self)
{
Image *images, *new_images;
ExceptionInfo *exception;
// Convert the image array to an image sequence.
images = images_from_imagelist(self);
exception = AcquireExceptionInfo();
new_images = CoalesceImages(images, exception);
rm_split(images);
rm_check_exception(exception, new_images, DestroyOnError);
(void) DestroyExceptionInfo(exception);
rm_ensure_result(new_images);
return rm_imagelist_from_images(new_images);
}
|
#collect(&block) ⇒ Object Also known as: __map__
override Enumerable#collect
1402 1403 1404 1405 1406 1407 1408 1409 |
# File 'lib/rmagick_internal.rb', line 1402 def collect(&block) current = get_current a = @images.collect(&block) ilist = self.class.new a.each { |image| ilist << image } ilist.set_current current ilist end |
#collect!(&block) ⇒ Object Also known as: map!, __map__!
1411 1412 1413 1414 1415 |
# File 'lib/rmagick_internal.rb', line 1411 def collect!(&block) @images.collect!(&block) is_an_image_array @images self end |
#combine(*args) ⇒ Object
Combines the images using the specified colorspace.
Ruby usage:
- @verbatim new_image = ImageList#combine @endverbatim
- @verbatim new_image = ImageList#combine(colorspace) @endverbatim
Notes:
- Calls CombineImages.
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'ext/RMagick/rmilist.c', line 202
VALUE ImageList_combine(int argc, VALUE *argv, VALUE self)
{
ChannelType channel;
ColorspaceType colorspace, old_colorspace;
long len;
Image *images, *new_image;
ExceptionInfo *exception;
len = check_imagelist_length(self);
switch (argc)
{
case 1:
VALUE_TO_ENUM(argv[0], colorspace, ColorspaceType);
break;
case 0:
colorspace = sRGBColorspace;
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (expected 1, got %d)", argc);
break;
}
channel = RedChannel;
switch (len)
{
case 5:
if (colorspace == CMYKColorspace)
channel |= AlphaChannel;
else
rb_raise(rb_eArgError, "invalid number of images in this image list");
case 4:
if (colorspace == CMYKColorspace)
channel |= IndexChannel;
else
channel |= AlphaChannel;
case 3:
channel |= GreenChannel;
channel |= BlueChannel;
break;
case 2:
channel |= AlphaChannel;
break;
case 1:
break;
default:
rb_raise(rb_eArgError, "invalid number of images in this image list");
break;
}
images = images_from_imagelist(self);
old_colorspace = images->colorspace;
SetImageColorspace(images, colorspace);
exception = AcquireExceptionInfo();
new_image = CombineImages(images, channel, exception);
rm_split(images);
images->colorspace = old_colorspace;
rm_check_exception(exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#compact ⇒ Object
1440 1441 1442 1443 1444 1445 1446 1447 |
# File 'lib/rmagick_internal.rb', line 1440 def compact current = get_current ilist = self.class.new a = @images.compact a.each { |image| ilist << image } ilist.set_current current ilist end |
#compact! ⇒ Object
1449 1450 1451 1452 1453 1454 |
# File 'lib/rmagick_internal.rb', line 1449 def compact! current = get_current a = @images.compact! # returns nil if no changes were made set_current current a.nil? ? nil : self end |
#composite_layers(*args) ⇒ Object
Equivalent to convert’s -layers composite option.
Ruby usage:
- @verbatim ImageList#composite_layers(images) @endverbatim
- @verbatim ImageList#composite_layers(images,operator) @endverbatim
Notes:
- Default operator is OverCompositeOp
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'ext/RMagick/rmilist.c', line 285
VALUE
ImageList_composite_layers(int argc, VALUE *argv, VALUE self)
{
VALUE source_images;
Image *dest, *source, *new_images;
RectangleInfo geometry;
CompositeOperator operator = OverCompositeOp;
ExceptionInfo *exception;
switch (argc)
{
case 2:
VALUE_TO_ENUM(argv[1], operator, CompositeOperator);
case 1:
source_images = argv[0];
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (expected 1 or 2, got %d)", argc);
break;
}
// Convert ImageLists to image sequences.
dest = images_from_imagelist(self);
new_images = clone_imagelist(dest);
rm_split(dest);
source = images_from_imagelist(source_images);
SetGeometry(new_images,&geometry);
(void) ParseAbsoluteGeometry(new_images->geometry, &geometry);
geometry.width = source->page.width != 0 ? source->page.width : source->columns;
geometry.height = source->page.height != 0 ? source->page.height : source->rows;
GravityAdjustGeometry(new_images->page.width != 0 ? new_images->page.width : new_images->columns
, new_images->page.height != 0 ? new_images->page.height : new_images->rows
, new_images->gravity, &geometry);
exception = AcquireExceptionInfo();
CompositeLayers(new_images, operator, source, geometry.x, geometry.y, exception);
rm_split(source);
rm_check_exception(exception, new_images, DestroyOnError);
(void) DestroyExceptionInfo(exception);
RB_GC_GUARD(source_images);
return rm_imagelist_from_images(new_images);
}
|
#concat(other) ⇒ Object
1456 1457 1458 1459 1460 1461 |
# File 'lib/rmagick_internal.rb', line 1456 def concat(other) is_an_image_array other other.each { |image| @images << image } @scene = length - 1 self end |
#copy ⇒ Object
Make a deep copy
1418 1419 1420 1421 1422 1423 1424 |
# File 'lib/rmagick_internal.rb', line 1418 def copy ditto = self.class.new @images.each { |f| ditto << f.copy } ditto.scene = @scene ditto.taint if tainted? ditto end |
#cur_image ⇒ Object
Return the current image
1427 1428 1429 1430 |
# File 'lib/rmagick_internal.rb', line 1427 def cur_image Kernel.raise IndexError, 'no images in this list' unless @scene @images[@scene] end |
#deconstruct ⇒ Object
Compare each image with the next in a sequence and returns the maximum bounding region of any pixel differences it discovers.
Ruby usage:
- @verbatim ImageList#deconstruct @endverbatim
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'ext/RMagick/rmilist.c', line 344
VALUE
ImageList_deconstruct(VALUE self)
{
Image *new_images, *images;
ExceptionInfo *exception;
images = images_from_imagelist(self);
exception = AcquireExceptionInfo();
new_images = DeconstructImages(images, exception);
rm_split(images);
rm_check_exception(exception, new_images, DestroyOnError);
(void) DestroyExceptionInfo(exception);
rm_ensure_result(new_images);
return rm_imagelist_from_images(new_images);
}
|
#delay=(d) ⇒ Object
Set same delay for all images
1464 1465 1466 1467 1468 |
# File 'lib/rmagick_internal.rb', line 1464 def delay=(d) raise ArgumentError, 'delay must be greater than or equal to 0' if Integer(d) < 0 @images.each { |f| f.delay = Integer(d) } end |
#delete(obj, &block) ⇒ Object
1470 1471 1472 1473 1474 1475 1476 |
# File 'lib/rmagick_internal.rb', line 1470 def delete(obj, &block) is_an_image obj current = get_current a = @images.delete(obj, &block) set_current current a end |
#delete_at(ndx) ⇒ Object
1478 1479 1480 1481 1482 1483 |
# File 'lib/rmagick_internal.rb', line 1478 def delete_at(ndx) current = get_current a = @images.delete_at(ndx) set_current current a end |
#delete_if(&block) ⇒ Object
1485 1486 1487 1488 1489 1490 |
# File 'lib/rmagick_internal.rb', line 1485 def delete_if(&block) current = get_current @images.delete_if(&block) set_current current self end |
#display ⇒ Object Also known as: __display__
Display all the images to an X window screen.
Ruby usage:
- @verbatim ImageList#display @endverbatim
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
# File 'ext/RMagick/rmilist.c', line 372
VALUE
ImageList_display(VALUE self)
{
Image *images;
Info *info;
VALUE info_obj;
// Create a new Info object to use with this call
info_obj = rm_info_new();
Data_Get_Struct(info_obj, Info, info);
// Convert the images array to an images sequence.
images = images_from_imagelist(self);
(void) DisplayImages(info, images);
rm_split(images);
rm_check_image_exception(images, RetainOnError);
RB_GC_GUARD(info_obj);
return self;
}
|
#dup ⇒ Object
1492 1493 1494 1495 1496 1497 1498 |
# File 'lib/rmagick_internal.rb', line 1492 def dup ditto = self.class.new @images.each { |img| ditto << img } ditto.scene = @scene ditto.taint if tainted? ditto end |
#eql?(other) ⇒ Boolean
1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 |
# File 'lib/rmagick_internal.rb', line 1500 def eql?(other) is_an_image_array other eql = other.eql?(@images) begin # "other" is another ImageList eql &&= @scene == other.scene rescue NoMethodError # "other" is a plain Array end eql end |
#fill(*args, &block) ⇒ Object
1511 1512 1513 1514 1515 1516 1517 1518 |
# File 'lib/rmagick_internal.rb', line 1511 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
1521 1522 1523 1524 1525 1526 1527 1528 |
# File 'lib/rmagick_internal.rb', line 1521 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 ilist end |
#flatten_images ⇒ Object
Merge all the images into a single image.
Ruby usage:
- @verbatim ImageList#flatten_images @endverbatim
Notes:
- Can't use "flatten" because that's an Array method
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 |
# File 'ext/RMagick/rmilist.c', line 408
VALUE
ImageList_flatten_images(VALUE self)
{
Image *images, *new_image;
ExceptionInfo *exception;
images = images_from_imagelist(self);
exception = AcquireExceptionInfo();
new_image = MergeImageLayers(images, FlattenLayer, exception);
rm_split(images);
rm_check_exception(exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#from_blob(*blobs, &block) ⇒ Object
1531 1532 1533 1534 1535 1536 1537 1538 |
# File 'lib/rmagick_internal.rb', line 1531 def from_blob(*blobs, &block) Kernel.raise ArgumentError, 'no blobs given' if blobs.length.zero? blobs.each do |b| Magick::Image.from_blob(b, &block).each { |n| @images << n } end @scene = length - 1 self end |
#insert(index, *args) ⇒ Object
1553 1554 1555 1556 1557 1558 1559 |
# File 'lib/rmagick_internal.rb', line 1553 def insert(index, *args) args.each { |image| is_an_image image } current = get_current @images.insert(index, *args) set_current current self end |
#inspect ⇒ Object
Call inspect for all the images
1562 1563 1564 1565 1566 |
# File 'lib/rmagick_internal.rb', line 1562 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
1569 1570 1571 1572 1573 1574 |
# File 'lib/rmagick_internal.rb', line 1569 def iterations=(n) n = Integer(n) Kernel.raise ArgumentError, 'iterations must be between 0 and 65535' if n < 0 || n > 65_535 @images.each { |f| f.iterations = n } self end |
#last(*args) ⇒ Object
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 |
# File 'lib/rmagick_internal.rb', line 1576 def last(*args) if args.length.zero? a = @images.last else a = @images.last(*args) ilist = self.class.new a.each { |img| ilist << img } @scene = a.length - 1 a = ilist end a end |
#marshal_dump ⇒ Object
Custom marshal/unmarshal for Ruby 1.8.
1590 1591 1592 1593 1594 |
# File 'lib/rmagick_internal.rb', line 1590 def marshal_dump ary = [@scene] @images.each { |i| ary << Marshal.dump(i) } ary end |
#marshal_load(ary) ⇒ Object
1596 1597 1598 1599 1600 |
# File 'lib/rmagick_internal.rb', line 1596 def marshal_load(ary) @scene = ary.shift @images = [] ary.each { |a| @images << Marshal.load(a) } end |
#montage ⇒ Object
Call MontageImages.
Ruby usage:
- @verbatim ImageList#montage <{parm block}> @endverbatim
Notes:
- Creates Montage object, yields to block if present in Montage object's
scope.
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 |
# File 'ext/RMagick/rmilist.c', line 442
VALUE
ImageList_montage(VALUE self)
{
VALUE montage_obj;
Montage *montage;
Image *new_images, *images;
ExceptionInfo *exception;
// Create a new instance of the Magick::Montage class
montage_obj = rm_montage_new();
if (rb_block_given_p())
{
// Run the block in the instance's context, allowing the app to modify the
// object's attributes.
(void) rb_obj_instance_eval(0, NULL, montage_obj);
}
Data_Get_Struct(montage_obj, Montage, montage);
images = images_from_imagelist(self);
for (Image *image = images; image; image = GetNextImageInList(image))
{
if (montage->compose != UndefinedCompositeOp)
{
image->compose = montage->compose;
}
image->background_color = montage->info->background_color;
image->border_color = montage->info->border_color;
image->matte_color = montage->info->matte_color;
image->gravity = montage->info->gravity;
}
exception = AcquireExceptionInfo();
// MontageImage can return more than one image.
new_images = MontageImages(images, montage->info, exception);
rm_split(images);
rm_check_exception(exception, new_images, DestroyOnError);
(void) DestroyExceptionInfo(exception);
rm_ensure_result(new_images);
RB_GC_GUARD(montage_obj);
return rm_imagelist_from_images(new_images);
}
|
#morph(nimages) ⇒ Object
Requires a minimum of two images. The first image is transformed into the second by a number of intervening images as specified by “number_images”.
Ruby usage:
- @verbatim ImageList#morph(number_images) @endverbatim
Notes:
- Sets \@scenes to 0
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 |
# File 'ext/RMagick/rmilist.c', line 505
VALUE
ImageList_morph(VALUE self, VALUE nimages)
{
Image *images, *new_images;
ExceptionInfo *exception;
long number_images;
// Use a signed long so we can test for a negative argument.
number_images = NUM2LONG(nimages);
if (number_images <= 0)
{
rb_raise(rb_eArgError, "number of intervening images must be > 0");
}
images = images_from_imagelist(self);
exception = AcquireExceptionInfo();
new_images = MorphImages(images, (unsigned long)number_images, exception);
rm_split(images);
rm_check_exception(exception, new_images, DestroyOnError);
(void) DestroyExceptionInfo(exception);
rm_ensure_result(new_images);
return rm_imagelist_from_images(new_images);
}
|
#mosaic ⇒ Object
Merge all the images into a single image.
Ruby usage:
- @verbatim ImageList#mosaic @endverbatim
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 |
# File 'ext/RMagick/rmilist.c', line 542
VALUE
ImageList_mosaic(VALUE self)
{
Image *images, *new_image;
ExceptionInfo *exception;
images = images_from_imagelist(self);
exception = AcquireExceptionInfo();
new_image = MergeImageLayers(images, MosaicLayer, exception);
rm_split(images);
rm_check_exception(exception, new_image, DestroyOnError);
(void) DestroyExceptionInfo(exception);
rm_ensure_result(new_image);
return rm_image_new(new_image);
}
|
#new_image(cols, rows, *fill, &info_blk) ⇒ Object
Create a new image and add it to the end
1620 1621 1622 |
# File 'lib/rmagick_internal.rb', line 1620 def new_image(cols, rows, *fill, &info_blk) self << Magick::Image.new(cols, rows, *fill, &info_blk) end |
#optimize_layers(method) ⇒ Object
Equivalent to -layers option in ImageMagick 6.2.6.
Ruby usage:
- @verbatim ImageList#optimize_layers(method) @endverbatim
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 |
# File 'ext/RMagick/rmilist.c', line 573
VALUE
ImageList_optimize_layers(VALUE self, VALUE method)
{
Image *images, *new_images, *new_images2;
LayerMethod mthd;
ExceptionInfo *exception;
QuantizeInfo quantize_info;
new_images2 = NULL; // defeat "unused variable" message
VALUE_TO_ENUM(method, mthd, LayerMethod);
images = images_from_imagelist(self);
exception = AcquireExceptionInfo();
switch (mthd)
{
case CoalesceLayer:
new_images = CoalesceImages(images, exception);
break;
case DisposeLayer:
new_images = DisposeImages(images, exception);
break;
case OptimizeTransLayer:
new_images = clone_imagelist(images);
OptimizeImageTransparency(new_images, exception);
break;
case RemoveDupsLayer:
new_images = clone_imagelist(images);
RemoveDuplicateLayers(&new_images, exception);
break;
case RemoveZeroLayer:
new_images = clone_imagelist(images);
RemoveZeroDelayLayers(&new_images, exception);
break;
case CompositeLayer:
rm_split(images);
(void) DestroyExceptionInfo(exception);
rb_raise(rb_eNotImpError, "Magick::CompositeLayer is not supported. Use the composite_layers method instead.");
break;
// In 6.3.4-ish, OptimizeImageLayer replaced OptimizeLayer
case OptimizeImageLayer:
new_images = OptimizeImageLayers(images, exception);
break;
// and OptimizeLayer became a "General Purpose, GIF Animation Optimizer" (ref. mogrify.c)
case OptimizeLayer:
new_images = CoalesceImages(images, exception);
rm_split(images);
rm_check_exception(exception, new_images, DestroyOnError);
new_images2 = OptimizeImageLayers(new_images, exception);
DestroyImageList(new_images);
rm_check_exception(exception, new_images2, DestroyOnError);
new_images = new_images2;
OptimizeImageTransparency(new_images, exception);
rm_check_exception(exception, new_images, DestroyOnError);
// mogrify supports -dither here. We don't.
GetQuantizeInfo(&quantize_info);
(void) RemapImages(&quantize_info, new_images, NULL);
break;
case OptimizePlusLayer:
new_images = OptimizePlusImageLayers(images, exception);
break;
case CompareAnyLayer:
case CompareClearLayer:
case CompareOverlayLayer:
new_images = CompareImageLayers(images, mthd, exception);
break;
case MosaicLayer:
new_images = MergeImageLayers(images, mthd, exception);
break;
case FlattenLayer:
new_images = MergeImageLayers(images, mthd, exception);
break;
case MergeLayer:
new_images = MergeImageLayers(images, mthd, exception);
break;
case TrimBoundsLayer:
new_images = MergeImageLayers(images, mthd, exception);
break;
default:
rm_split(images);
(void) DestroyExceptionInfo(exception);
rb_raise(rb_eArgError, "undefined layer method");
break;
}
rm_split(images);
rm_check_exception(exception, new_images, DestroyOnError);
(void) DestroyExceptionInfo(exception);
rm_ensure_result(new_images);
return rm_imagelist_from_images(new_images);
}
|
#partition(&block) ⇒ Object
1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 |
# File 'lib/rmagick_internal.rb', line 1624 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
1636 1637 1638 1639 1640 1641 1642 1643 |
# File 'lib/rmagick_internal.rb', line 1636 def ping(*files, &block) Kernel.raise ArgumentError, 'no files given' if files.length.zero? files.each do |f| Magick::Image.ping(f, &block).each { |n| @images << n } end @scene = length - 1 self end |
#pop ⇒ Object
1645 1646 1647 1648 1649 1650 |
# File 'lib/rmagick_internal.rb', line 1645 def pop current = get_current a = @images.pop # can return nil set_current current a end |
#push(*objs) ⇒ Object
1652 1653 1654 1655 1656 1657 1658 1659 |
# File 'lib/rmagick_internal.rb', line 1652 def push(*objs) objs.each do |image| is_an_image image @images << image end @scene = length - 1 self end |
#quantize(*args) ⇒ Object
Call QuantizeImages.
Ruby usage:
- @verbatim ImageList#quantize @endverbatim
- @verbatim ImageList#quantize(number_colors) @endverbatim
- @verbatim ImageList#quantize(number_colors, colorspace) @endverbatim
- @verbatim ImageList#quantize(number_colors, colorspace, dither) @endverbatim
- @verbatim ImageList#quantize(number_colors, colorspace, dither, tree_depth) @endverbatim
- @verbatim ImageList#quantize(number_colors, colorspace, dither, tree_depth, measure_error) @endverbatim
Notes:
- Default number_colors is 256
- Default coorspace is Magick::RGBColorsapce
- Default dither is true
- Default tree_depth is 0
- Default measure_error is false
- Sets \@scene to the same value as self.scene
899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 |
# File 'ext/RMagick/rmilist.c', line 899
VALUE
ImageList_quantize(int argc, VALUE *argv, VALUE self)
{
Image *images, *new_images;
Image *new_image;
QuantizeInfo quantize_info;
ExceptionInfo *exception;
VALUE new_imagelist, scene;
GetQuantizeInfo(&quantize_info);
switch (argc)
{
case 5:
quantize_info.measure_error = (MagickBooleanType) RTEST(argv[4]);
case 4:
quantize_info.tree_depth = (unsigned long)NUM2INT(argv[3]);
case 3:
if (rb_obj_is_kind_of(argv[2], Class_DitherMethod))
{
VALUE_TO_ENUM(argv[2], quantize_info.dither_method, DitherMethod);
quantize_info.dither = quantize_info.dither_method != NoDitherMethod;
}
else
{
quantize_info.dither = (MagickBooleanType) RTEST(argv[2]);
}
case 2:
VALUE_TO_ENUM(argv[1], quantize_info.colorspace, ColorspaceType);
case 1:
quantize_info.number_colors = NUM2ULONG(argv[0]);
case 0:
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 5)", argc);
break;
}
// Convert image array to image sequence, clone image sequence.
images = images_from_imagelist(self);
exception = AcquireExceptionInfo();
new_images = CloneImageList(images, exception);
rm_split(images);
rm_check_exception(exception, new_images, DestroyOnError);
rm_ensure_result(new_images);
(void) QuantizeImages(&quantize_info, new_images);
rm_check_exception(exception, new_images, DestroyOnError);
(void) DestroyExceptionInfo(exception);
// Create new ImageList object, convert mapped image sequence to images,
// append to images array.
new_imagelist = ImageList_new();
while ((new_image = RemoveFirstImageFromList(&new_images)))
{
imagelist_push(new_imagelist, rm_image_new(new_image));
}
// Set @scene in new ImageList object to same value as in self.
scene = rb_iv_get(self, "@scene");
(void) rb_iv_set(new_imagelist, "@scene", scene);
RB_GC_GUARD(new_imagelist);
RB_GC_GUARD(scene);
return new_imagelist;
}
|
#read(*files, &block) ⇒ Object
Read files and concatenate the new images
1662 1663 1664 1665 1666 1667 1668 1669 |
# File 'lib/rmagick_internal.rb', line 1662 def read(*files, &block) Kernel.raise ArgumentError, 'no files given' if files.length.zero? files.each do |f| Magick::Image.read(f, &block).each { |n| @images << n } end @scene = length - 1 self end |
#reject(&block) ⇒ Object
override Enumerable’s reject
1672 1673 1674 1675 1676 1677 1678 1679 |
# File 'lib/rmagick_internal.rb', line 1672 def reject(&block) current = get_current ilist = self.class.new a = @images.reject(&block) a.each { |image| ilist << image } ilist.set_current current ilist end |
#reject!(&block) ⇒ Object
1681 1682 1683 1684 1685 1686 1687 |
# File 'lib/rmagick_internal.rb', line 1681 def reject!(&block) current = get_current a = @images.reject!(&block) @images = a unless a.nil? set_current current a.nil? ? nil : self end |
#remap(*args) ⇒ Object Also known as: affinity
Call RemapImages.
Ruby usage:
- @verbatim ImageList#remap @endverbatim
- @verbatim ImageList#remap(remap_image) @endverbatim
- @verbatim ImageList#remap(remap_image, dither_method) @endverbatim
Notes:
- Default remap_image is nil
- Default dither_method is RiemersmaDitherMethod
- Modifies images in-place.
989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 |
# File 'ext/RMagick/rmilist.c', line 989
VALUE
ImageList_remap(int argc, VALUE *argv, VALUE self)
{
Image *images, *remap_image = NULL;
QuantizeInfo quantize_info;
if (argc > 0 && argv[0] != Qnil)
{
VALUE t = rm_cur_image(argv[0]);
remap_image = rm_check_destroyed(t);
RB_GC_GUARD(t);
}
GetQuantizeInfo(&quantize_info);
if (argc > 1)
{
VALUE_TO_ENUM(argv[1], quantize_info.dither_method, DitherMethod);
quantize_info.dither = MagickTrue;
}
if (argc > 2)
{
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
}
images = images_from_imagelist(self);
(void) RemapImages(&quantize_info, images, remap_image);
rm_check_image_exception(images, RetainOnError);
rm_split(images);
return self;
}
|
#replace(other) ⇒ Object
1689 1690 1691 1692 1693 1694 1695 1696 1697 |
# File 'lib/rmagick_internal.rb', line 1689 def replace(other) is_an_image_array other current = get_current @images.clear other.each { |image| @images << image } @scene = length.zero? ? nil : 0 set_current current self end |
#respond_to?(meth_id, priv = false) ⇒ Boolean
1701 1702 1703 1704 1705 1706 1707 1708 1709 |
# File 'lib/rmagick_internal.rb', line 1701 def respond_to?(meth_id, priv = false) return true if __respond_to__?(meth_id, priv) if @scene @images[@scene].respond_to?(meth_id, priv) else super end end |
#reverse ⇒ Object
1711 1712 1713 1714 1715 1716 1717 |
# File 'lib/rmagick_internal.rb', line 1711 def reverse current = get_current a = self.class.new @images.reverse_each { |image| a << image } a.set_current current a end |
#reverse! ⇒ Object
1719 1720 1721 1722 1723 1724 |
# File 'lib/rmagick_internal.rb', line 1719 def reverse! current = get_current @images.reverse! set_current current self end |
#reverse_each ⇒ Object
1726 1727 1728 1729 |
# File 'lib/rmagick_internal.rb', line 1726 def reverse_each @images.reverse_each { |image| yield(image) } self end |
#shift ⇒ Object
1731 1732 1733 1734 1735 1736 |
# File 'lib/rmagick_internal.rb', line 1731 def shift current = get_current a = @images.shift set_current current a end |
#slice(*args) ⇒ Object
1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 |
# File 'lib/rmagick_internal.rb', line 1738 def slice(*args) slice = @images.slice(*args) if slice ilist = self.class.new if slice.respond_to?(:each) slice.each { |image| ilist << image } else ilist << slice end else ilist = nil end ilist end |
#slice!(*args) ⇒ Object
1753 1754 1755 1756 1757 1758 |
# File 'lib/rmagick_internal.rb', line 1753 def slice!(*args) current = get_current a = @images.slice!(*args) set_current current a end |
#ticks_per_second=(t) ⇒ Object
1760 1761 1762 1763 |
# File 'lib/rmagick_internal.rb', line 1760 def ticks_per_second=(t) Kernel.raise ArgumentError, 'ticks_per_second must be greater than or equal to 0' if Integer(t) < 0 @images.each { |f| f.ticks_per_second = Integer(t) } end |
#to_a ⇒ Object
1765 1766 1767 1768 1769 |
# File 'lib/rmagick_internal.rb', line 1765 def to_a a = [] @images.each { |image| a << image } a end |
#to_blob ⇒ Object
Return the imagelist as a blob (a String).
Ruby usage:
- @verbatim ImageList#to_blob @endverbatim
Notes:
- Runs an info parm block if present - the user can specify the image
format and depth
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 |
# File 'ext/RMagick/rmilist.c', line 1038
VALUE
ImageList_to_blob(VALUE self)
{
Image *images, *image;
Info *info;
VALUE info_obj;
VALUE blob_str;
void *blob = NULL;
size_t length = 0;
ExceptionInfo *exception;
info_obj = rm_info_new();
Data_Get_Struct(info_obj, Info, info);
// Convert the images array to an images sequence.
images = images_from_imagelist(self);
exception = AcquireExceptionInfo();
(void) SetImageInfo(info, MagickTrue, exception);
rm_check_exception(exception, images, RetainOnError);
if (*info->magick != '\0')
{
Image *img;
for (img = images; img; img = GetNextImageInList(img))
{
strncpy(img->magick, info->magick, sizeof(info->magick)-1);
}
}
for (image = images; image; image = GetNextImageInList(image))
{
rm_sync_image_options(image, info);
}
// Unconditionally request multi-images support. The worst that
// can happen is that there's only one image or the format
// doesn't support multi-image files.
info->adjoin = MagickTrue;
blob = ImagesToBlob(info, images, &length, exception);
if (blob && exception->severity >= ErrorException)
{
magick_free((void*)blob);
blob = NULL;
length = 0;
}
rm_split(images);
CHECK_EXCEPTION()
(void) DestroyExceptionInfo(exception);
if (length == 0 || !blob)
{
return Qnil;
}
blob_str = rb_str_new(blob, (long)length);
magick_free((void*)blob);
RB_GC_GUARD(info_obj);
RB_GC_GUARD(blob_str);
return blob_str;
}
|
#uniq ⇒ Object
1771 1772 1773 1774 1775 1776 1777 |
# File 'lib/rmagick_internal.rb', line 1771 def uniq current = get_current a = self.class.new @images.uniq.each { |image| a << image } a.set_current current a end |
#uniq!(*_args) ⇒ Object
1779 1780 1781 1782 1783 1784 |
# File 'lib/rmagick_internal.rb', line 1779 def uniq!(*_args) current = get_current a = @images.uniq! set_current current a.nil? ? nil : self end |
#unshift(obj) ⇒ Object
1787 1788 1789 1790 1791 1792 |
# File 'lib/rmagick_internal.rb', line 1787 def unshift(obj) is_an_image obj @images.unshift(obj) @scene = 0 self end |
#values_at(*args) ⇒ Object Also known as: indexes, indices
1794 1795 1796 1797 1798 1799 1800 |
# File 'lib/rmagick_internal.rb', line 1794 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 a end |
#write(file) ⇒ Object
Write all the images to the specified file. If the file format supports multi-image files, and the ‘images’ array contains more than one image, then the images will be written as a single multi-image file. Otherwise each image will be written to a separate file.
Ruby usage:
- @verbatim ImageList#write(file) @endverbatim
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 |
# File 'ext/RMagick/rmilist.c', line 1117
VALUE
ImageList_write(VALUE self, VALUE file)
{
Image *images, *img;
Info *info;
const MagickInfo *m;
VALUE info_obj;
unsigned long scene;
ExceptionInfo *exception;
info_obj = rm_info_new();
Data_Get_Struct(info_obj, Info, info);
if (TYPE(file) == T_FILE)
{
rb_io_t *fptr;
// Ensure file is open - raise error if not
GetOpenFile(file, fptr);
#if defined(_WIN32)
add_format_prefix(info, fptr->pathv);
SetImageInfoFile(info, NULL);
#else
SetImageInfoFile(info, rb_io_stdio_file(fptr));
#endif
}
else
{
add_format_prefix(info, file);
SetImageInfoFile(info, NULL);
}
// Convert the images array to an images sequence.
images = images_from_imagelist(self);
// Copy the filename into each image. Set a scene number to be used if
// writing multiple files. (Ref: ImageMagick's utilities/convert.c
for (scene = 0, img = images; img; img = GetNextImageInList(img))
{
img->scene = scene++;
strcpy(img->filename, info->filename);
}
// Find out if the format supports multi-images files.
exception = AcquireExceptionInfo();
(void) SetImageInfo(info, MagickTrue, exception);
rm_check_exception(exception, images, RetainOnError);
m = GetMagickInfo(info->magick, exception);
rm_check_exception(exception, images, RetainOnError);
(void) DestroyExceptionInfo(exception);
// Tell WriteImage if we want a multi-images file.
if (imagelist_length(self) > 1L && GetMagickAdjoin(m))
{
info->adjoin = MagickTrue;
}
for (img = images; img; img = GetNextImageInList(img))
{
rm_sync_image_options(img, info);
(void) WriteImage(info, img);
// images will be split before raising an exception
rm_check_image_exception(images, RetainOnError);
if (info->adjoin)
{
break;
}
}
rm_split(images);
RB_GC_GUARD(info_obj);
return self;
}
|