Class: MagickWand::Wand
- Inherits:
-
Object
- Object
- MagickWand::Wand
- Includes:
- Comparable, Enumerable
- Defined in:
- lib/magickwand.rb,
ext/magickwand/wand.c
Instance Method Summary collapse
-
#+(obj2) ⇒ Object
objc = obja + objb creates a new wand from the images in obja and objb.
-
#<<(obj2) ⇒ Object
(also: #concat)
wand1 << wand2 concats images in wand2 to wand1.
-
#<=>(other) ⇒ Object
wanda <=> wandb Comparison is similar to how arrays are compared.
- #[](*args) ⇒ Object (also: #slice)
- #[]=(*args) ⇒ Object
-
#add_canvas(*args) ⇒ Object
wand.add_canvas(width, height = width, background = “white”) default height is same as width.
-
#animate(*args) ⇒ Object
wand.animate(:delay => ticks, :iterations => 0) wand.animate(:delay => [ticks, ticks-per-second]).
-
#annotate(*args) ⇒ Object
wand.annotate(text, :x=>0.0, :y=>0.0, :angle=>0.0 [, drawing_wand options]).
-
#background ⇒ Object
returns the background color property for the 0th image.
-
#blur(*args) ⇒ Object
wand.blur(radius, sigma, :channel=>“default”).
-
#border(*args) ⇒ Object
wand.border(color, width=1, height=width).
-
#bordercolor ⇒ Object
returns the border color property for the 0th image.
-
#bordercolor=(color) ⇒ Object
sets the border color property for the 0th image.
-
#colors ⇒ Object
colors = wand.colors.
-
#comment ⇒ Object
string = img.comment Gets the comment from the first image There is no official “MagickGetComment” API for this operation.
-
#comment=(comment) ⇒ Object
img.comment = string # set comment to string img.comment = nil # removes comment.
-
#compare(*args) ⇒ Object
diff, distortion = wand.compare(wand2[, :metric=>“ae”, :channel=>“default”, :fuzz=>“0%”) Compares the first image in wand to the first image in wand2. ‘wand’ is the reconstructed image, ‘wand2’ is the reference image. Returns a difference image and distortion metric..
-
#composite(*args) ⇒ Object
wand.composite(composite_wand, :compose=>“over”, :x=>0, :y=>0, :gravity=>“center”).
-
#crop(*args) ⇒ Object
wand.crop(width, height=width, :x=>x, :y=y, :gravity=gravity, :repage=boolean) x and y default to 0 gravity defaults to NorthWestGravity repage defaults to true.
-
#depth ⇒ Object
depth = wand.depth.
-
#dimensions ⇒ Object
- width, height
-
wand.dimensions returns width, height of 1st/only image.
- #display ⇒ Object (also: #__display__)
- #draw(drawing_obj) ⇒ Object
-
#each ⇒ Object
(>= 1.8.7) if no block return enumerator.
-
#empty? ⇒ Boolean
returns true if wand.length == 0.
-
#eql?(obj2) ⇒ Boolean
wand.eql?(wand2) returns true if wand <=> wand2 returns 0.
-
#export_pixels(*args) ⇒ Object
str = wand.export_pixels(x, y, width, height, :storage_type=>“char”, :map=>“rgb”).
- #filename ⇒ Object
-
#format ⇒ Object
format = wand.format.
-
#hash ⇒ Object
wand.hash is the same as wand.signature.hash.
-
#import_pixels(*args) ⇒ Object
wand.import_pixels(x, y, columns, rows, pixels, :map=>“rgb”, :storage_type=>“char”) imports into the first image in the wand.
-
#initialize ⇒ Object
constructor
wand = MagickWand::Wand.new accepts no arguments wand_allocate just creates an empty Wand structure.
-
#initialize_copy(obj2) ⇒ Object
wand2 = wand.dup wand2 = wand.clone.
-
#insert(index, obj2) ⇒ Object
wand.insert(index, wand2) Inserts images from wand2 before the image at the given index, modifying wand.
-
#inspect ⇒ Object
The inspect string is intended to be quite similar to the output of the identify command, without the -verbose option.
-
#length ⇒ Object
(also: #size)
Wand#length - the number of images in the wand.
-
#modulate(*args) ⇒ Object
Brightness is required.
-
#page ⇒ Object
- width, height, x, y
-
wand.page.
-
#ping(*args) ⇒ Object
Does not read pixel data.
-
#ping_string(*args) ⇒ Object
Does not read pixel data.
-
#read(*args) ⇒ Object
An image filename is mandantory, optionally followed by an options hash.
-
#read_string(*args) ⇒ Object
wand.read_string(string,…) Reads one or more images from the string into the wand and adds them to the end of the image list.
-
#resize(*args) ⇒ Object
resizes all the images in the wand to the specified dimensions wand.resize(width, height=width, options) valid options are :filter, :blur.
-
#resize_to_fill(width, height = nil, options = nil) ⇒ Object
options are :filter, :blur, :gravity, :repage.
-
#resize_to_fit(width, height = nil, options = nil) ⇒ Object
options are :filter, :blur.
-
#resolution ⇒ Object
x-res, y-res = wand.resolution Retreives the resolution from the first image.
-
#rotate(*args) ⇒ Object
wand.rotate(degrees, background = “white”).
-
#sharpen(*args) ⇒ Object
wand.sharpen(radius, sigma, :channel=“default”).
-
#signature ⇒ Object
return 64-hex digit signature of the first image.
-
#slice!(*args) ⇒ Object
wand.slice!(2) => deletes and returns a wand containing the 3rd image wand.slice!(3..6) => deletes and returns a wand containing images 4, 5, 6.
-
#strip ⇒ Object
wand.strip().
-
#type ⇒ Object
(also: #__type__)
type = wand.type.
-
#write(*args) ⇒ Object
wand.write(filename, :adjoin=>true).
-
#write_string(*args) ⇒ Object
string = wand.write_string returns the images as a string.
Constructor Details
#initialize ⇒ Object
wand = MagickWand::Wand.new accepts no arguments wand_allocate just creates an empty Wand structure. Here we add a new, empty MagickWand.
1570 1571 1572 1573 1574 1575 1576 1577 1578 |
# File 'ext/magickwand/wand.c', line 1570
static VALUE wand_initialize(VALUE obj)
{
Wand *wand;
Data_Get_Struct(obj, Wand, wand);
wand->magickwand = NewMagickWand();
return obj;
}
|
Instance Method Details
#+(obj2) ⇒ Object
objc = obja + objb creates a new wand from the images in obja and objb
1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 |
# File 'ext/magickwand/wand.c', line 1718
static VALUE wand_plus(VALUE obj, VALUE obj2)
{
Wand *wand, *wand2;
MagickWand *temp, *new_magickwand;
Data_Get_Struct(obj, Wand, wand);
Data_Get_Struct(obj2, Wand, wand2);
new_magickwand = CloneMagickWand(wand->magickwand);
MagickResetIterator(wand2->magickwand);
while (MagickNextImage(wand2->magickwand) != MagickFalse)
{
MagickSetLastIterator(new_magickwand);
temp = MagickGetImage(wand2->magickwand);
mwr_check_magickwand_error(wand2->magickwand);
MagickAddImage(new_magickwand, temp);
temp = DestroyMagickWand(temp);
mwr_check_magickwand_error(new_magickwand);
}
return wand_new(new_magickwand);
}
|
#<<(obj2) ⇒ Object Also known as: concat
wand1 << wand2 concats images in wand2 to wand1
889 890 891 892 893 894 895 896 897 898 899 900 901 902 |
# File 'ext/magickwand/wand.c', line 889
static VALUE wand_concat(VALUE obj, VALUE obj2)
{
Wand *wand, *wand2;
rb_check_frozen(obj);
Data_Get_Struct(obj, Wand, wand);
Data_Get_Struct(obj2, Wand, wand2);
MagickSetLastIterator(wand->magickwand);
MagickAddImage(wand->magickwand, wand2->magickwand);
mwr_check_magickwand_error(wand->magickwand);
return obj;
}
|
#<=>(other) ⇒ Object
wanda <=> wandb Comparison is similar to how arrays are compared. Each image in each wand is compared by their signatures. If all images are equal then the longer wand is > than the shorter wand.
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/magickwand/wand.c', line 624
static VALUE wand_cmp(VALUE obj, VALUE other)
{
Wand *wand, *other_wand;
int cmp;
char *signature, *other_signature;
if (obj == other)
{
return INT2FIX(0);
}
Data_Get_Struct(obj, Wand, wand);
Data_Get_Struct(other, Wand, other_wand);
MagickResetIterator(wand->magickwand);
MagickResetIterator(other_wand->magickwand);
cmp = 0;
while (cmp == 0 && MagickNextImage(wand->magickwand) && MagickNextImage(other_wand->magickwand))
{
signature = MagickGetImageSignature(wand->magickwand);
other_signature = MagickGetImageSignature(other_wand->magickwand);
cmp = strcmp(signature, other_signature);
RelinquishMagickMemory(signature);
RelinquishMagickMemory(other_signature);
}
if (cmp != 0)
{
return INT2FIX(cmp);
}
if (MagickHasNextImage(wand->magickwand))
{
return INT2FIX(1);
}
if (MagickHasNextImage(other_wand->magickwand))
{
return INT2FIX(-1);
}
return INT2FIX(0);
}
|
#[](*args) ⇒ Object Also known as: slice
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 332 333 |
# File 'ext/magickwand/wand.c', line 302
static VALUE wand_aref(int argc, VALUE *argv, VALUE obj)
{
long nimages, begin, length;
volatile VALUE range_code;
if (argc == 2)
{
return subsequence(obj, FIX2LONG(argv[0]), FIX2LONG(argv[1]));
}
else if (TYPE(argv[0]) == T_FIXNUM)
{
return subsequence(obj, FIX2LONG(argv[0]), 1L);
}
else
{
nimages = FIX2LONG(wand_length(obj));
// Returns Qfalse if argv[0] isn't a Range object.
// Returns Qnil if out-of-range
range_code = rb_range_beg_len(argv[0], &begin, &length, nimages, 0);
if (range_code == Qnil)
{
return wand_new(NULL);
}
else if (range_code == Qfalse)
{
rb_raise(rb_eTypeError, "expecting Fixnum or Range, got %s", rb_obj_classname(argv[0]));
}
return subsequence(obj, begin, length);
}
}
|
#[]=(*args) ⇒ Object
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 |
# File 'ext/magickwand/wand.c', line 414
static VALUE wand_aset(int argc, VALUE *argv, VALUE obj)
{
Wand *wand;
volatile VALUE range_code;
long nimages, begin, length;
rb_check_frozen(obj);
if (argc == 3)
{
return splice(obj, FIX2LONG(argv[0]), FIX2LONG(argv[1]), argv[2]);
}
else if (argc == 2)
{
if (rb_obj_is_kind_of(argv[0], rb_cRange))
{
Data_Get_Struct(obj, Wand, wand);
nimages = (long) MagickGetNumberImages(wand->magickwand);
range_code = rb_range_beg_len(argv[0], &begin, &length, nimages, 2);
return splice(obj, begin, length, argv[1]);
}
else
{
return splice(obj, FIX2LONG(argv[0]), 1UL, argv[1]);
}
}
else
{
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)", argc);
}
return (VALUE)0; // not reachable
}
|
#add_canvas(*args) ⇒ Object
wand.add_canvas(width, height = width, background = “white”) default height is same as width
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 84 85 86 87 88 89 90 91 92 93 |
# File 'ext/magickwand/wand.c', line 48
static VALUE wand_add_canvas(int argc, VALUE *argv, VALUE obj)
{
Wand *wand;
PixelWand *pixelwand;
Image *new_image;
volatile VALUE width, height, background;
unsigned long columns, rows;
char *background_color = "white";
rb_check_frozen(obj);
switch (rb_scan_args(argc, argv, "12", &width, &height, &background))
{
case 3:
background_color = StringValuePtr(background);
// fall through
case 2:
rows = NUM2ULONG(height);
columns = NUM2ULONG(width);
break;
case 1:
rows = columns = NUM2ULONG(width);
break;
}
Data_Get_Struct(obj, Wand, wand);
pixelwand = NewPixelWand();
PixelSetColor(pixelwand, background_color);
mwr_check_pixelwand_error(pixelwand);
// New images are added at the end.
MagickSetLastIterator(wand->magickwand);
// The image background color is NOT taken from the pixelwand!
// This must be done separately.
if (MagickNewImage(wand->magickwand, columns, rows, pixelwand) != MagickFalse)
{
new_image = GetImageFromMagickWand(wand->magickwand);
mwr_get_pixelpacket_from_pixelwand(&new_image->background_color, pixelwand);
SetImageBackgroundColor(new_image);
}
DestroyPixelWand(pixelwand);
mwr_check_magickwand_error(wand->magickwand);
return obj;
}
|
#animate(*args) ⇒ Object
wand.animate(:delay => ticks, :iterations => 0) wand.animate(:delay => [ticks, ticks-per-second])
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'ext/magickwand/wand.c', line 102
static VALUE wand_animate(int argc, VALUE *argv, VALUE obj)
{
Wand *wand;
volatile VALUE v;
VALUE options;
unsigned long delay = ULONG_MAX, iterations = ULONG_MAX;
long ticks_per_second = LONG_MAX;
int xyzzy = 1;
Data_Get_Struct(obj, Wand, wand);
if (MagickGetNumberImages(wand->magickwand) == 0UL)
{
return obj;
}
(void) rb_scan_args(argc, argv, "01", &options);
if (options != Qnil)
{
v = rb_hash_aref(options, ID2SYM(rb_intern("delay")));
if (v != Qnil)
{
if (TYPE(v) == T_ARRAY)
{
delay = NUM2ULONG(rb_ary_entry(v, 0));
// For simplicity, allow the array to have only 1 entry
if (NUM2INT(rb_funcall(v, rb_intern("length"), 0)) > 1)
{
ticks_per_second = NUM2ULONG(rb_ary_entry(v, 1));
}
}
else
{
delay = NUM2ULONG(v);
}
}
v = rb_hash_aref(options, ID2SYM(rb_intern("iterations")));
if (v != Qnil)
{
iterations = NUM2ULONG(v);
}
v = rb_hash_aref(options, ID2SYM(rb_intern("xyzzy")));
if (v != Qnil)
{
xyzzy = RTEST(v);
}
}
if (delay != ULONG_MAX || iterations != ULONG_MAX)
{
MagickResetIterator(wand->magickwand);
while (MagickNextImage(wand->magickwand) != MagickFalse)
{
if (iterations != ULONG_MAX)
{
MagickSetImageIterations(wand->magickwand, iterations);
mwr_check_magickwand_error(wand->magickwand);
}
if (delay != ULONG_MAX)
{
MagickSetImageDelay(wand->magickwand, delay);
mwr_check_magickwand_error(wand->magickwand);
}
if (ticks_per_second != LONG_MAX)
{
MagickSetImageTicksPerSecond(wand->magickwand, ticks_per_second);
mwr_check_magickwand_error(wand->magickwand);
}
}
}
// :xyzzy => false suppresses the actual animation (for testing)
if (xyzzy)
{
MagickAnimateImages(wand->magickwand, NULL);
mwr_check_magickwand_error(wand->magickwand);
}
return obj;
}
|
#annotate(*args) ⇒ Object
wand.annotate(text, :x=>0.0, :y=>0.0, :angle=>0.0 [, drawing_wand options])
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'ext/magickwand/wand.c', line 253
static VALUE wand_annotate(int argc, VALUE *argv, VALUE obj)
{
Wand *wand;
Drawing *drawing;
double x, y, angle;
volatile VALUE graphics_context;
VALUE v, text, options;
char *text_string;
rb_check_frozen(obj);
(void)rb_scan_args(argc, argv, "11", &text, &options);
text_string = StringValuePtr(text);
if (RSTRING_LEN(text) == 0)
{
rb_raise(rb_eArgError, "no text specified");
}
x = mwr_get_option(options, "x", &v) ? NUM2DBL(v) : 0.0;
y = mwr_get_option(options, "y", &v) ? NUM2DBL(v) : 0.0;
angle = mwr_get_option(options, "angle", &v) ? NUM2DBL(v) : 0.0;
graphics_context = mwr_drawing_new();
Data_Get_Struct(graphics_context, Drawing, drawing);
// Override default NorthWest gravity. It's useless.
DrawSetGravity(drawing->wand, CenterGravity);
mwr_process_options(graphics_context, options);
Data_Get_Struct(obj, Wand, wand);
MagickResetIterator(wand->magickwand);
while (MagickNextImage(wand->magickwand) != MagickFalse)
{
MagickAnnotateImage(wand->magickwand, drawing->wand, x, y, angle, text_string);
}
return obj;
}
|
#background ⇒ Object
returns the background color property for the 0th image
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
# File 'ext/magickwand/wand.c', line 454
static VALUE wand_background(VALUE obj)
{
Wand *wand;
Image *image;
if (FIX2LONG(wand_length(obj)) == 0)
{
return Qnil;
}
Data_Get_Struct(obj, Wand, wand);
MagickResetIterator(wand->magickwand);
image = GetImageFromMagickWand(wand->magickwand);
mwr_check_magickwand_error(wand->magickwand);
return mwr_pixelpacket_to_hex(image, &image->background_color);
}
|
#blur(*args) ⇒ Object
wand.blur(radius, sigma, :channel=>“default”)
573 574 575 576 |
# File 'ext/magickwand/wand.c', line 573
static VALUE wand_blur(int argc, VALUE *argv, VALUE obj)
{
return convolve(argc, argv, obj, MagickBlurImageChannel);
}
|
#border(*args) ⇒ Object
wand.border(color, width=1, height=width)
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 |
# File 'ext/magickwand/wand.c', line 584
static VALUE wand_border(int argc, VALUE *argv, VALUE obj)
{
Wand *wand;
PixelWand *pixelwand;
VALUE color, wt, ht;
char *bordercolor;
unsigned long width, height;
rb_check_frozen(obj);
(void) rb_scan_args(argc, argv, "12", &color, &wt, &ht);
bordercolor = StringValuePtr(color);
width = wt != Qnil ? NUM2ULONG(wt) : 1UL;
height = ht != Qnil ? NUM2ULONG(ht) : width;
pixelwand = NewPixelWand();
PixelSetColor(pixelwand, bordercolor);
mwr_check_pixelwand_error(pixelwand);
Data_Get_Struct(obj, Wand, wand);
MagickResetIterator(wand->magickwand);
while (MagickNextImage(wand->magickwand) != MagickFalse)
{
MagickBorderImage(wand->magickwand, pixelwand, width, height);
mwr_check_magickwand_error(wand->magickwand);
}
DestroyPixelWand(pixelwand);
return obj;
}
|
#bordercolor ⇒ Object
returns the border color property for the 0th image
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
# File 'ext/magickwand/wand.c', line 477
static VALUE wand_bordercolor(VALUE obj)
{
Wand *wand;
PixelWand *bordercolor;
Image *image;
volatile VALUE color;
if (FIX2LONG(wand_length(obj)) == 0)
{
return Qnil;
}
Data_Get_Struct(obj, Wand, wand);
MagickResetIterator(wand->magickwand);
bordercolor = NewPixelWand();
MagickGetImageBorderColor(wand->magickwand, bordercolor);
mwr_check_magickwand_error(wand->magickwand);
image = GetImageFromMagickWand(wand->magickwand);
mwr_check_magickwand_error(wand->magickwand);
color = mwr_pixelwand_to_hex(image, bordercolor);
DestroyPixelWand(bordercolor);
return color;
}
|
#bordercolor=(color) ⇒ Object
sets the border color property for the 0th image
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 |
# File 'ext/magickwand/wand.c', line 511
static VALUE wand_bordercolor_set(VALUE obj, VALUE color)
{
Wand *wand;
PixelWand *pixelwand;
char *bordercolor;
rb_check_frozen(obj);
Data_Get_Struct(obj, Wand, wand);
bordercolor = StringValuePtr(color);
pixelwand = NewPixelWand();
PixelSetColor(pixelwand, bordercolor);
mwr_check_pixelwand_error(pixelwand);
MagickResetIterator(wand->magickwand);
while (MagickNextImage(wand->magickwand) != MagickFalse)
{
(void) MagickSetImageBorderColor(wand->magickwand, pixelwand);
mwr_check_magickwand_error(wand->magickwand);
}
DestroyPixelWand(pixelwand);
return color;
}
|
#colors ⇒ Object
colors = wand.colors
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 |
# File 'ext/magickwand/wand.c', line 673
static VALUE wand_colors(VALUE obj)
{
Wand *wand;
unsigned long colors;
Data_Get_Struct(obj, Wand, wand);
if (MagickGetNumberImages(wand->magickwand) == 0UL)
{
return Qnil;
}
MagickResetIterator(wand->magickwand);
colors = MagickGetImageColors(wand->magickwand);
mwr_check_magickwand_error(wand->magickwand);
return ULONG2NUM(colors);
}
|
#comment ⇒ Object
string = img.comment Gets the comment from the first image There is no official “MagickGetComment” API for this operation.
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 |
# File 'ext/magickwand/wand.c', line 698
static VALUE wand_comment(VALUE obj)
{
Image *magick_image;
Wand *wand;
const ImageAttribute *comment;
Data_Get_Struct(obj, Wand, wand);
MagickSetFirstIterator(wand->magickwand);
magick_image = GetImageFromMagickWand(wand->magickwand);
mwr_check_magickwand_error(wand->magickwand);
if (magick_image)
{
comment = GetImageAttribute(magick_image, "comment");
if (comment && comment->value)
{
return rb_str_new2(comment->value);
}
}
return Qnil;
}
|
#comment=(comment) ⇒ Object
img.comment = string # set comment to string img.comment = nil # removes comment
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 |
# File 'ext/magickwand/wand.c', line 727
static VALUE wand_comment_set(VALUE obj, VALUE comment)
{
const char *comment_str = NULL;
Wand *wand;
rb_check_frozen(obj);
Data_Get_Struct(obj, Wand, wand);
if (comment != Qnil)
{
comment_str = StringValuePtr(comment);
}
MagickResetIterator(wand->magickwand);
while (MagickNextImage(wand->magickwand) != MagickFalse)
{
(void) MagickCommentImage(wand->magickwand, comment_str);
mwr_check_magickwand_error(wand->magickwand);
}
return comment;
}
|
#compare(*args) ⇒ Object
diff, distortion = wand.compare(wand2[, :metric=>“ae”, :channel=>“default”, :fuzz=>“0%”) Compares the first image in wand to the first image in wand2. ‘wand’ is the reconstructed image, ‘wand2’ is the reference image. Returns a difference image and distortion metric.
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 |
# File 'ext/magickwand/wand.c', line 759
static VALUE wand_compare(int argc, VALUE *argv, VALUE obj)
{
Wand *wand;
Wand *wand2;
MagickWand *result;
VALUE other, options, v;
MetricType metric;
ChannelType channels;
double distortion = 0.0;
double fuzz = 0.0;
(void) rb_scan_args(argc, argv, "11", &other, &options);
(void) mwr_get_option(options, "metric", &v);
metric = mwr_string_to_metrictype(v, AbsoluteErrorMetric, RaiseUndefinedOption);
(void) mwr_get_option(options, "channel", &v);
channels = mwr_string_to_channeltype(v, DefaultChannels, RaiseUndefinedOption);
Data_Get_Struct(obj, Wand, wand);
Data_Get_Struct(other, Wand, wand2);
MagickResetIterator(wand->magickwand);
MagickResetIterator(wand2->magickwand);
(void) mwr_get_option(options, "fuzz", &v);
#if defined(HAVE_MAGICKSETIMAGEFUZZ)
if (v != Qnil)
{
if (rb_obj_is_kind_of(v, rb_cNumeric))
{
fuzz = NUM2DBL(v);
}
else
{
v = rb_String(v);
// StringToDouble is defined in magick/string.c
fuzz = StringToDouble(StringValuePtr(v), QuantumRange+1.0);
}
}
MagickSetImageFuzz(wand->magickwand, fuzz);
#else
if (v != Qnil)
{
rb_warning("MagickWand: The :fuzz option is not supported with this release of ImageMagick.");
fuzz = fuzz;
}
#endif
result = MagickCompareImageChannels(wand->magickwand, wand2->magickwand, channels, metric, &distortion);
mwr_check_magickwand_error(wand->magickwand);
mwr_check_magickwand_error(wand2->magickwand);
return rb_ary_new3(2, wand_new(result), rb_float_new(distortion));
}
|
#composite(*args) ⇒ Object
wand.composite(composite_wand, :compose=>“over”, :x=>0, :y=>0, :gravity=>“center”)
Composites each image in composite_wand over the image in the corresponding position in wand. If the composite_wand has fewer images than wand, then its images are reused.
The position of the upper-left corner of the composite image is x,y, as adjusted by gravity, relative to the current image and current composite image.
827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 |
# File 'ext/magickwand/wand.c', line 827
static VALUE wand_composite(int argc, VALUE *argv, VALUE obj)
{
volatile VALUE obj2;
VALUE v, options;
Wand *wand, *composite_wand;
CompositeOperator compose;
GravityType gravity;
unsigned long columns, rows;
long x, y;
RectangleInfo rect;
rb_check_frozen(obj);
(void) rb_scan_args(argc, argv, "11", &obj2, &options);
Data_Get_Struct(obj, Wand, wand);
Data_Get_Struct(obj2, Wand, composite_wand);
if (MagickGetNumberImages(wand->magickwand) == 0UL || MagickGetNumberImages(composite_wand->magickwand) == 0)
{
return obj;
}
memset(&rect, 0, sizeof(rect));
(void) mwr_get_option(options, "compose", &v);
compose = mwr_string_to_composetype(v, OverCompositeOp, RaiseUndefinedOption);
(void) mwr_get_option(options, "gravity", &v);
gravity = mwr_string_to_gravitytype(v, CenterGravity, RaiseUndefinedOption);
x = mwr_get_option(options, "x", &v) ? FIX2LONG(v) : 0L;
y = mwr_get_option(options, "y", &v) ? FIX2LONG(v) : 0L;
MagickResetIterator(wand->magickwand);
MagickResetIterator(composite_wand->magickwand);
while (MagickNextImage(wand->magickwand) != MagickFalse)
{
if (MagickNextImage(composite_wand->magickwand) == MagickFalse)
{
MagickResetIterator(composite_wand->magickwand);
MagickNextImage(composite_wand->magickwand);
}
// Position is based on the size of the current image
columns = MagickGetImageWidth(wand->magickwand);
rows = MagickGetImageHeight(wand->magickwand);
rect.width = MagickGetImageWidth(composite_wand->magickwand);
rect.height = MagickGetImageHeight(composite_wand->magickwand);
rect.x = x;
rect.y = y;
(void) GravityAdjustGeometry(columns, rows, gravity, &rect);
(void) MagickCompositeImage(wand->magickwand, composite_wand->magickwand, compose, rect.x, rect.y);
mwr_check_magickwand_error(wand->magickwand);
}
return obj;
}
|
#crop(*args) ⇒ Object
wand.crop(width, height=width, :x=>x, :y=y, :gravity=gravity, :repage=boolean) x and y default to 0 gravity defaults to NorthWestGravity repage defaults to true
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 969 970 971 972 973 974 975 976 |
# File 'ext/magickwand/wand.c', line 913
static VALUE wand_crop(int argc, VALUE *argv, VALUE obj)
{
Wand *wand;
Image *image;
volatile VALUE width, height, options;
VALUE v;
unsigned long columns, rows;
long x, y;
GravityType gravity;
GravityType keep_gravity;
int repage;
RectangleInfo rect;
char geometry[200];
ExceptionInfo exception;
rb_check_frozen(obj);
(void) rb_scan_args(argc, argv, "12", &width, &height, &options);
columns = NUM2ULONG(width);
if (height != Qnil)
{
rows = NUM2ULONG(height);
}
else
{
rows = columns;
}
(void) mwr_get_option(options, "gravity", &v);
gravity = mwr_string_to_gravitytype(v, NorthWestGravity, RaiseUndefinedOption);
x = mwr_get_option(options, "x", &v) ? FIX2LONG(v) : 0L;
y = mwr_get_option(options, "y", &v) ? FIX2LONG(v) : 0L;
repage = mwr_get_option(options, "repage", &v) ? RTEST(v) : 1;
(void) sprintf(geometry, "%lux%lu%+ld%+ld", columns, rows, x, y);
Data_Get_Struct(obj, Wand, wand);
GetExceptionInfo(&exception);
MagickResetIterator(wand->magickwand);
// Crop each image individually. If they're different sizes then the
// crop rectangle could be different.
while (MagickNextImage(wand->magickwand) != MagickFalse)
{
image = GetImageFromMagickWand(wand->magickwand);
mwr_check_magickwand_error(wand->magickwand);
keep_gravity = image->gravity;
image->gravity = gravity;
memset(&rect, 0, sizeof(rect));
(void) ParseGravityGeometry(image, geometry, &rect, &exception);
MagickCropImage(wand->magickwand, rect.width, rect.height, rect.x, rect.y);
image->gravity = keep_gravity;
mwr_check_magickwand_error(wand->magickwand);
if (repage)
{
MagickResetImagePage(wand->magickwand, "0x0+0+0");
mwr_check_magickwand_error(wand->magickwand);
}
}
DestroyExceptionInfo(&exception);
return obj;
}
|
#depth ⇒ Object
depth = wand.depth
984 985 986 987 988 989 990 991 992 993 994 995 996 |
# File 'ext/magickwand/wand.c', line 984
static VALUE wand_depth(VALUE obj)
{
Wand *wand;
Data_Get_Struct(obj, Wand, wand);
if (MagickGetNumberImages(wand->magickwand) == 0UL)
{
return Qnil;
}
MagickResetIterator(wand->magickwand);
return ULONG2NUM(MagickGetImageDepth(wand->magickwand));
}
|
#dimensions ⇒ Object
- width, height
-
wand.dimensions
returns width, height of 1st/only image
1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 |
# File 'ext/magickwand/wand.c', line 1005
static VALUE wand_dimensions(VALUE obj)
{
Wand *wand;
volatile VALUE dimensions;
unsigned long width, height;
Data_Get_Struct(obj, Wand, wand);
if (MagickGetNumberImages(wand->magickwand) == 0UL)
{
return Qnil;
}
MagickResetIterator(wand->magickwand);
dimensions = rb_ary_new2(2);
width = MagickGetImageWidth(wand->magickwand);
mwr_check_magickwand_error(wand->magickwand);
rb_ary_push(dimensions, ULONG2NUM(width));
height = MagickGetImageHeight(wand->magickwand);
mwr_check_magickwand_error(wand->magickwand);
rb_ary_push(dimensions, ULONG2NUM(height));
return dimensions;
}
|
#display ⇒ Object Also known as: __display__
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 |
# File 'ext/magickwand/wand.c', line 1035
static VALUE wand_display(VALUE obj)
{
Wand *wand;
Data_Get_Struct(obj, Wand, wand);
if (MagickGetNumberImages(wand->magickwand) == 0UL)
{
return Qnil;
}
MagickDisplayImages(wand->magickwand, NULL);
mwr_check_magickwand_error(wand->magickwand);
return obj;
}
|
#draw(drawing_obj) ⇒ Object
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 |
# File 'ext/magickwand/wand.c', line 1052
static VALUE wand_draw(VALUE obj, VALUE drawing_obj)
{
Wand *wand;
Drawing *drawing;
rb_check_frozen(obj);
Data_Get_Struct(obj, Wand, wand);
Data_Get_Struct(drawing_obj, Drawing, drawing);
MagickResetIterator(wand->magickwand);
while (MagickNextImage(wand->magickwand) != MagickFalse)
{
MagickDrawImage(wand->magickwand, drawing->wand);
mwr_check_magickwand_error(wand->magickwand);
}
return obj;
}
|
#each ⇒ Object
(>= 1.8.7) if no block return enumerator
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/magickwand/wand.c', line 1077
static VALUE wand_each(VALUE obj)
{
Wand *wand;
unsigned long n, nimages;
#if defined(HAVE_RB_ENUMERATORIZE)
if (!rb_block_given_p())
{
return rb_enumeratorize(obj, ID2SYM(rb_frame_this_func()), 0, 0);
}
#endif
Data_Get_Struct(obj, Wand, wand);
// Can't use the typical Reset/GetNext loop here. The block
// may change the wand's iterator.
nimages = MagickGetNumberImages(wand->magickwand);
for (n = 0; n < nimages; n++)
{
MagickSetIteratorIndex(wand->magickwand, n);
rb_yield(wand_new(MagickGetImage(wand->magickwand)));
}
return obj;
}
|
#empty? ⇒ Boolean
returns true if wand.length == 0
1109 1110 1111 1112 1113 1114 1115 |
# File 'ext/magickwand/wand.c', line 1109
static VALUE wand_empty(VALUE obj)
{
Wand *wand;
Data_Get_Struct(obj, Wand, wand);
return MagickGetNumberImages(wand->magickwand) == 0UL ? Qtrue : Qfalse;
}
|
#eql?(obj2) ⇒ Boolean
wand.eql?(wand2) returns true if wand <=> wand2 returns 0
1124 1125 1126 1127 1128 1129 1130 |
# File 'ext/magickwand/wand.c', line 1124
static VALUE wand_eql(VALUE obj, VALUE obj2)
{
volatile VALUE eql;
eql = wand_cmp(obj, obj2);
return FIX2INT(eql) == 0 ? Qtrue : Qfalse;
}
|
#export_pixels(*args) ⇒ Object
str = wand.export_pixels(x, y, width, height, :storage_type=>“char”, :map=>“rgb”)
1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 |
# File 'ext/magickwand/wand.c', line 1175
static VALUE wand_export_pixels(int argc, VALUE *argv, VALUE obj)
{
Wand *wand;
VALUE x_off, y_off, width, height, options, v, pixels;
long x, y, length;
unsigned long columns, rows;
StorageType stg_type;
char *map;
size_t stg_type_size;
(void) rb_scan_args(argc, argv, "41", &x_off, &y_off, &width, &height, &options);
x = FIX2LONG(x_off);
y = FIX2LONG(y_off);
columns = NUM2ULONG(width);
rows = NUM2ULONG(height);
(void) mwr_get_option(options, "map", &v);
map = v != Qnil ? StringValuePtr(v) : "RGB";
(void) mwr_get_option(options, "storage_type", &v);
stg_type = mwr_string_to_storagetype(v, CharPixel, RaiseUndefinedOption);
stg_type_size = get_stg_type_size(stg_type);
if (strlen(map) == 0)
{
rb_raise(rb_eArgError, "no map specified");
}
length = (long) (columns * rows * strlen(map) * stg_type_size);
// Allocate a string long enough to hold the exported pixel data.
pixels = rb_str_new2("");
(void) rb_str_resize(pixels, length);
Data_Get_Struct(obj, Wand, wand);
MagickResetIterator(wand->magickwand);
MagickExportImagePixels(wand->magickwand, x, y, columns, rows, map, stg_type, RSTRING_PTR(pixels));
mwr_check_magickwand_error(wand->magickwand);
return pixels;
}
|
#filename ⇒ Object
1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 |
# File 'ext/magickwand/wand.c', line 1218
static VALUE wand_filename(VALUE obj)
{
Wand *wand;
char *f;
volatile VALUE filename;
Data_Get_Struct(obj, Wand, wand);
if (MagickGetNumberImages(wand->magickwand) == 0UL)
{
return Qnil;
}
MagickResetIterator(wand->magickwand);
f = MagickGetImageFilename(wand->magickwand);
mwr_check_magickwand_error(wand->magickwand);
filename = rb_str_new2(f);
MagickRelinquishMemory(f);
return filename;
}
|
#format ⇒ Object
format = wand.format
1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 |
# File 'ext/magickwand/wand.c', line 1246
static VALUE wand_format(VALUE obj)
{
Wand *wand;
char *f;
volatile VALUE format;
Data_Get_Struct(obj, Wand, wand);
if (MagickGetNumberImages(wand->magickwand) == 0UL)
{
return Qnil;
}
MagickResetIterator(wand->magickwand);
f = MagickGetImageFormat(wand->magickwand);
mwr_check_magickwand_error(wand->magickwand);
format = rb_str_new2(f);
MagickRelinquishMemory(f);
return format;
}
|
#hash ⇒ Object
wand.hash is the same as wand.signature.hash
1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 |
# File 'ext/magickwand/wand.c', line 1357
static VALUE wand_hash(VALUE obj)
{
volatile VALUE signature;
Wand *wand;
Data_Get_Struct(obj, Wand, wand);
if (MagickGetNumberImages(wand->magickwand) == 0UL)
{
return INT2FIX(0);
}
signature = wand_signature(obj);
return INT2FIX(rb_str_hash(signature));
}
|
#import_pixels(*args) ⇒ Object
wand.import_pixels(x, y, columns, rows, pixels, :map=>“rgb”, :storage_type=>“char”) imports into the first image in the wand
1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 |
# File 'ext/magickwand/wand.c', line 1309
static VALUE wand_import_pixels(int argc, VALUE *argv, VALUE obj)
{
Wand *wand;
VALUE columns, rows, pixels, options, x_off, y_off, v;
unsigned long width, height, length;
long x, y;
void *data;
StorageType stg_type;
char *map;
size_t stg_type_size;
rb_check_frozen(obj);
(void) rb_scan_args(argc, argv, "51", &x_off, &y_off, &columns, &rows, &pixels, &options);
x = NUM2LONG(x_off);
y = NUM2LONG(y_off);
width = NUM2ULONG(columns);
height = NUM2ULONG(rows);
StringValue(pixels);
data = (void *) RSTRING_PTR(pixels);
length = (unsigned long) RSTRING_LEN(pixels);
(void) mwr_get_option(options, "map", &v);
map = v != Qnil ? StringValuePtr(v) : "RGB";
(void) mwr_get_option(options, "storage_type", &v);
stg_type = mwr_string_to_storagetype(v, CharPixel, RaiseUndefinedOption);
stg_type_size = get_stg_type_size(stg_type);
if (length < width*height*stg_type_size*strlen(map))
{
rb_raise(rb_eArgError, "pixel buffer too small (expecting %lu got %lu)",
width*height*stg_type_size*strlen(map), length);
}
Data_Get_Struct(obj, Wand, wand);
MagickResetIterator(wand->magickwand);
MagickImportImagePixels(wand->magickwand, x, y, width, height, map, stg_type, data);
mwr_check_magickwand_error(wand->magickwand);
return obj;
}
|
#initialize_copy(obj2) ⇒ Object
wand2 = wand.dup wand2 = wand.clone
1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 |
# File 'ext/magickwand/wand.c', line 1587
static VALUE wand_initialize_copy(VALUE obj, VALUE obj2)
{
Wand *wand, *wand2;
if (obj == obj2)
{
return obj;
}
Data_Get_Struct(obj, Wand, wand);
Data_Get_Struct(obj2, Wand, wand2);
wand->magickwand = CloneMagickWand(wand2->magickwand);
return obj;
}
|
#insert(index, obj2) ⇒ Object
wand.insert(index, wand2) Inserts images from wand2 before the image at the given index, modifying wand.
1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 |
# File 'ext/magickwand/wand.c', line 1380
static VALUE wand_insert(VALUE obj, VALUE index, VALUE obj2)
{
Wand *wand, *wand2;
long pos;
Data_Get_Struct(obj, Wand, wand);
Data_Get_Struct(obj2, Wand, wand2);
rb_check_frozen(obj);
pos = FIX2LONG(index);
if (pos == -1)
{
pos = (long) MagickGetNumberImages(wand->magickwand);
}
else if (pos < 0)
{
pos += 1;
}
return splice(obj, pos, 0, obj2);
}
|
#inspect ⇒ Object
The inspect string is intended to be quite similar to the output of the identify command, without the -verbose option. Largely lifted from ImageMagick’s IdentifyImage function.
1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 |
# File 'ext/magickwand/wand.c', line 1411
static VALUE wand_inspect(VALUE obj)
{
Wand *wand;
volatile VALUE inspect = rb_str_new2("(");
Image *image;
double elapsed_time;
double user_time;
unsigned long index = 0UL;
unsigned long columns, rows;
unsigned long width, height;
long x, y;
char *filename, *format;
char buff[MaxTextExtent];
ImageType image_type;
Data_Get_Struct(obj, Wand, wand);
if (MagickGetNumberImages(wand->magickwand) == 0UL)
{
return rb_str_new2("()");
}
MagickResetIterator(wand->magickwand);
while (MagickNextImage(wand->magickwand) != MagickFalse)
{
if (index > 0UL)
{
(void) rb_str_cat(inspect, "\n", 1);
}
image = GetImageFromMagickWand(wand->magickwand);
mwr_check_magickwand_error(wand->magickwand);
// magick_filename, filename
if (*image->magick_filename != '\0')
{
filename = MagickGetImageFilename(wand->magickwand);
if (strcmp(image->magick_filename, filename) != 0)
{
(void) rb_str_cat2(inspect, image->magick_filename);
(void) rb_str_cat(inspect, "=>", 2);
}
if (index == 0)
{
(void) rb_str_cat2(inspect, filename);
}
else
{
(void) rb_str_cat2(inspect, filename);
(void) sprintf(buff, "[%lu]", index);
(void) rb_str_cat2(inspect, buff);
}
MagickRelinquishMemory(filename);
}
// format
format = MagickGetImageFormat(wand->magickwand);
if (*format != '\0')
{
(void) sprintf(buff, " %s", format);
(void) rb_str_cat2(inspect, buff);
}
MagickRelinquishMemory(format);
(void) rb_str_cat(inspect, " ", 1);
// dimensions
columns = MagickGetImageWidth(wand->magickwand);
rows = MagickGetImageHeight(wand->magickwand);
if (image->magick_columns != 0 || image->magick_rows != 0)
{
if (image->magick_columns != columns || image->magick_rows != rows)
{
(void) sprintf(buff, "%lux%lu=>", image->magick_columns, image->magick_rows);
(void) rb_str_cat2(inspect, buff);
}
}
(void) sprintf(buff, "%lux%lu ", columns, rows);
(void) rb_str_cat2(inspect, buff);
// page
MagickGetImagePage(wand->magickwand, &width, &height, &x, &y);
if (width != 0 || height != 0 || x != 0 || y != 0)
{
(void) sprintf(buff,"%lux%lu%+ld%+ld ", width, height, x, y);
(void) rb_str_cat2(inspect, buff);
}
(void) sprintf(buff, "%lu-bit ", MagickGetImageDepth(wand->magickwand));
(void) rb_str_cat2(inspect, buff);
image_type = MagickGetImageType(wand->magickwand);
if (image_type != UndefinedType)
{
(void) rb_str_cat2(inspect, mwr_imagetype_to_s(image_type));
(void) rb_str_cat(inspect, " ", 1);
}
if (image->storage_class == DirectClass)
{
(void) rb_str_cat2(inspect, "DirectClass ");
if (image->total_colors != 0)
{
(void) rb_str_cat2(inspect, mwr_format_size(image->total_colors, buff));
}
}
else
{
(void) rb_str_cat2(inspect, "PseudoClass ");
if (image->total_colors <= image->colors)
{
(void) sprintf(buff, "%luc", image->colors);
}
else
{
(void) sprintf(buff, "%lu=>%luc", image->total_colors, image->colors);
}
(void) rb_str_cat2(inspect, buff);
}
if (image->error.mean_error_per_pixel != 0.0)
{
(void) sprintf(buff, ".%ld/%f/%fdb",(long) (image->error.mean_error_per_pixel+0.5),
image->error.normalized_mean_error, image->error.normalized_maximum_error);
(void) rb_str_cat2(inspect, buff);
}
if (GetBlobSize(image) != 0)
{
(void) rb_str_cat(inspect, " ", 1);
(void) rb_str_cat2(inspect, mwr_format_size(GetBlobSize(image), buff));
}
if (elapsed_time > 0.06)
{
elapsed_time = GetElapsedTime(&image->timer);
user_time = GetUserTime(&image->timer);
(void) sprintf(buff, " %0.3fu %ld:%02ld", user_time,
(long) (elapsed_time/60.0+0.5),(long) ceil(fmod(elapsed_time, 60.0)));
(void) rb_str_cat2(inspect, buff);
}
index += 1UL;
}
rb_str_cat(inspect, ")", 1);
return inspect;
}
|
#length ⇒ Object Also known as: size
Wand#length - the number of images in the wand
1609 1610 1611 1612 1613 1614 1615 |
# File 'ext/magickwand/wand.c', line 1609
static VALUE wand_length(VALUE obj)
{
Wand *wand;
Data_Get_Struct(obj, Wand, wand);
return LONG2FIX((long)MagickGetNumberImages(wand->magickwand));
}
|
#modulate(*args) ⇒ Object
Brightness is required. Saturation and hue default to 100% (no change). Same defaults as the -modulate option. See magick/enhance.c.
1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 |
# File 'ext/magickwand/wand.c', line 1624
static VALUE wand_modulate(int argc, VALUE *argv, VALUE obj)
{
Wand *wand;
volatile VALUE brightness, saturation, hue;
double h, s, l;
rb_check_frozen(obj);
(void) rb_scan_args(argc, argv, "12", &brightness, &saturation, &hue);
l = NUM2DBL(brightness);
s = saturation != Qnil ? NUM2DBL(saturation) : 100.0;
h = hue != Qnil ? NUM2DBL(hue) : 100.0;
Data_Get_Struct(obj, Wand, wand);
MagickResetIterator(wand->magickwand);
while (MagickNextImage(wand->magickwand) != MagickFalse)
{
MagickModulateImage(wand->magickwand, l, s, h);
mwr_check_magickwand_error(wand->magickwand);
}
return obj;
}
|
#page ⇒ Object
- width, height, x, y
-
wand.page
1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 |
# File 'ext/magickwand/wand.c', line 1685
static VALUE wand_page(VALUE obj)
{
Wand *wand;
volatile VALUE page;
unsigned long width, height;
long x, y;
Data_Get_Struct(obj, Wand, wand);
if (MagickGetNumberImages(wand->magickwand) == 0UL)
{
return Qnil;
}
MagickResetIterator(wand->magickwand);
MagickGetImagePage(wand->magickwand, &width, &height, &x, &y);
mwr_check_magickwand_error(wand->magickwand);
page = rb_ary_new2(4);
rb_ary_push(page, ULONG2NUM(width));
rb_ary_push(page, ULONG2NUM(height));
rb_ary_push(page, LONG2NUM(x));
rb_ary_push(page, LONG2NUM(y));
return page;
}
|
#ping(*args) ⇒ Object
Does not read pixel data. Gets only the image dimensions, type, and length. . An image filename is mandantory, optionally followed by an options hash. Multiple reads are possible. Each call adds the new images to the wand . .
1777 1778 1779 1780 |
# File 'ext/magickwand/wand.c', line 1777
static VALUE wand_ping(int argc, VALUE *argv, VALUE obj)
{
return read(argc, argv, obj, MagickPingImage);
}
|
#ping_string(*args) ⇒ Object
Does not read pixel data. Gets only the image dimensions, type, and length. . wand.ping_string(string,…) Reads one or more images from the string into the wand and adds them to the end of the image list.
1836 1837 1838 1839 |
# File 'ext/magickwand/wand.c', line 1836
static VALUE wand_ping_string(int argc, VALUE *argv, VALUE obj)
{
return read_string(argc, argv, obj, MagickPingImageBlob);
}
|
#read(*args) ⇒ Object
An image filename is mandantory, optionally followed by an options hash. Multiple reads are possible. Each call adds the new images to the wand.
1789 1790 1791 1792 |
# File 'ext/magickwand/wand.c', line 1789
static VALUE wand_read(int argc, VALUE *argv, VALUE obj)
{
return read(argc, argv, obj, MagickReadImage);
}
|
#read_string(*args) ⇒ Object
wand.read_string(string,…) Reads one or more images from the string into the wand and adds them to the end of the image list.
1848 1849 1850 1851 |
# File 'ext/magickwand/wand.c', line 1848
static VALUE wand_read_string(int argc, VALUE *argv, VALUE obj)
{
return read_string(argc, argv, obj, MagickReadImageBlob);
}
|
#resize(*args) ⇒ Object
resizes all the images in the wand to the specified dimensions wand.resize(width, height=width, options) valid options are :filter, :blur
1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 |
# File 'ext/magickwand/wand.c', line 1861
static VALUE wand_resize(int argc, VALUE *argv, VALUE obj)
{
Wand *wand;
volatile VALUE width, height, options;
VALUE v;
double blur = 1.0;
unsigned long columns, rows;
FilterTypes filter = UndefinedFilter;
rb_check_frozen(obj);
(void) rb_scan_args(argc, argv, "12", &width, &height, &options);
columns = NUM2ULONG(width);
rows = (height != Qnil) ? NUM2ULONG(height) : columns;
(void) mwr_get_option(options, "filter", &v);
filter = mwr_string_to_filtertypes(v, UndefinedFilter, RaiseUndefinedOption);
if (mwr_get_option(options, "blur", &v) && v != Qnil)
{
blur = NUM2DBL(v);
}
Data_Get_Struct(obj, Wand, wand);
MagickResetIterator(wand->magickwand);
while (MagickNextImage(wand->magickwand) != MagickFalse)
{
MagickResizeImage(wand->magickwand, columns, rows, filter, blur);
mwr_check_magickwand_error(wand->magickwand);
}
return obj;
}
|
#resize_to_fill(width, height = nil, options = nil) ⇒ Object
options are :filter, :blur, :gravity, :repage
17 18 19 20 21 22 23 24 |
# File 'lib/magickwand.rb', line 17 def resize_to_fill(width, height=nil, =nil) height ||= width ||= Hash.new new_width, new_height = get_resize_geometry("#{width}x#{height}^") resize(new_width, new_height, ) [:gravity] ||= "center" crop(width, height, ) end |
#resize_to_fit(width, height = nil, options = nil) ⇒ Object
options are :filter, :blur
10 11 12 13 14 |
# File 'lib/magickwand.rb', line 10 def resize_to_fit(width, height=nil, =nil) height ||= width new_width, new_height = get_resize_geometry("#{width}x#{height}") resize(new_width, new_height, ) end |
#resolution ⇒ Object
x-res, y-res = wand.resolution Retreives the resolution from the first image
1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 |
# File 'ext/magickwand/wand.c', line 1900
static VALUE wand_resolution(VALUE obj)
{
Wand *wand;
double x_res, y_res;
Data_Get_Struct(obj, Wand, wand);
MagickResetIterator(wand->magickwand);
(void) MagickGetImageResolution(wand->magickwand, &x_res, &y_res);
mwr_check_magickwand_error(wand->magickwand);
return rb_ary_new3(2, rb_float_new(x_res), rb_float_new(y_res));
}
|
#rotate(*args) ⇒ Object
wand.rotate(degrees, background = “white”)
1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 |
# File 'ext/magickwand/wand.c', line 1918
static VALUE wand_rotate(int argc, VALUE *argv, VALUE obj)
{
Wand *wand;
VALUE amount, background;
double degrees;
char *background_color = "white";
PixelWand *pixelwand;
rb_check_frozen(obj);
(void) rb_scan_args(argc, argv, "11", &amount, &background);
degrees = NUM2DBL(amount);
if (background != Qnil)
{
background_color = StringValuePtr(background);
}
pixelwand = NewPixelWand();
PixelSetColor(pixelwand, background_color);
mwr_check_pixelwand_error(pixelwand);
Data_Get_Struct(obj, Wand, wand);
MagickResetIterator(wand->magickwand);
while (MagickNextImage(wand->magickwand) != MagickFalse)
{
MagickRotateImage(wand->magickwand, pixelwand, degrees);
mwr_check_magickwand_error(wand->magickwand);
}
DestroyPixelWand(pixelwand);
return obj;
}
|
#sharpen(*args) ⇒ Object
wand.sharpen(radius, sigma, :channel=“default”)
2111 2112 2113 2114 |
# File 'ext/magickwand/wand.c', line 2111
static VALUE wand_sharpen(int argc, VALUE *argv, VALUE obj)
{
return convolve(argc, argv, obj, MagickSharpenImageChannel);
}
|
#signature ⇒ Object
return 64-hex digit signature of the first image. used to “compare” two wands for equality. returns nil if no images in wand. note: this is relatively slow operation the first time it’s called
2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 |
# File 'ext/magickwand/wand.c', line 2125
static VALUE wand_signature(VALUE obj)
{
Wand *wand;
char *sig;
volatile VALUE signature;
Data_Get_Struct(obj, Wand, wand);
if (MagickGetNumberImages(wand->magickwand) == 0UL)
{
return Qnil;
}
MagickSetFirstIterator(wand->magickwand);
sig = MagickGetImageSignature(wand->magickwand);
mwr_check_magickwand_error(wand->magickwand);
signature = rb_str_new2(sig);
RelinquishMagickMemory(sig);
return signature;
}
|
#slice!(*args) ⇒ Object
wand.slice!(2) => deletes and returns a wand containing the 3rd image wand.slice!(3..6) => deletes and returns a wand containing images 4, 5, 6
This code is essentially identical to rb_str_slice_bang in string.c.
2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 |
# File 'ext/magickwand/wand.c', line 2154
static VALUE wand_slice_bang(int argc, VALUE *argv, VALUE obj)
{
volatile VALUE result;
VALUE buf[3];
int i;
if (argc < 1 || 2 < argc)
{
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
}
rb_check_frozen(obj);
for (i = 0; i < argc; i++)
{
buf[i] = argv[i];
}
buf[i] = wand_new(NULL);
result = wand_aref(argc, buf, obj);
if (!NIL_P(result))
{
wand_aset(argc+1, buf, obj);
}
return result;
}
|
#strip ⇒ Object
wand.strip()
2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 |
# File 'ext/magickwand/wand.c', line 2187
static VALUE wand_strip(VALUE obj)
{
Wand *wand;
rb_check_frozen(obj);
Data_Get_Struct(obj, Wand, wand);
MagickResetIterator(wand->magickwand);
while (MagickNextImage(wand->magickwand) != MagickFalse)
{
MagickStripImage(wand->magickwand);
mwr_check_magickwand_error(wand->magickwand);
}
return obj;
}
|
#type ⇒ Object Also known as: __type__
type = wand.type
2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 |
# File 'ext/magickwand/wand.c', line 2209
static VALUE wand_type(VALUE obj)
{
Wand *wand;
ImageType image_type;
Data_Get_Struct(obj, Wand, wand);
if (MagickGetNumberImages(wand->magickwand) == 0UL)
{
return Qnil;
}
MagickResetIterator(wand->magickwand);
image_type = MagickGetImageType(wand->magickwand);
mwr_check_magickwand_error(wand->magickwand);
return rb_str_new2(mwr_imagetype_to_s(image_type));
}
|
#write(*args) ⇒ Object
wand.write(filename, :adjoin=>true)
2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 |
# File 'ext/magickwand/wand.c', line 2275
static VALUE wand_write(int argc, VALUE *argv, VALUE obj)
{
Wand *wand;
volatile VALUE name, options;
VALUE v;
MagickBooleanType adjoin = MagickTrue;
(void) rb_scan_args(argc, argv, "11", &name, &options);
if (mwr_get_option(options, "adjoin", &v))
{
adjoin = RTEST(v) ? MagickTrue : MagickFalse;
}
mwr_process_options(obj, options);
Data_Get_Struct(obj, Wand, wand);
MagickResetIterator(wand->magickwand);
MagickWriteImages(wand->magickwand, StringValuePtr(name), adjoin);
mwr_check_magickwand_error(wand->magickwand);
return obj;
}
|
#write_string(*args) ⇒ Object
string = wand.write_string returns the images as a string
2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 |
# File 'ext/magickwand/wand.c', line 2234
static VALUE wand_write_string(int argc, VALUE *argv, VALUE obj)
{
Wand *wand;
VALUE options;
volatile VALUE str;
unsigned char *blob;
size_t length;
unsigned long nimages;
Data_Get_Struct(obj, Wand, wand);
nimages = MagickGetNumberImages(wand->magickwand);
if (nimages == 0UL)
{
return Qnil;
}
(void) rb_scan_args(argc, argv, "01", &options);
mwr_process_options(obj, options);
MagickResetIterator(wand->magickwand);
if (nimages == 1UL)
{
blob = MagickGetImageBlob(wand->magickwand, &length);
}
else
{
blob = MagickGetImagesBlob(wand->magickwand, &length);
}
str = rb_str_new((char *)blob, (long)length);
RelinquishMagickMemory(blob);
return str;
}
|