forked from Imagick/imagick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
imagick_class.c
14237 lines (11557 loc) Β· 374 KB
/
imagick_class.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
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
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
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
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
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
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
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
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
813
814
815
816
817
818
819
820
821
822
823
824
825
826
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
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
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
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
+----------------------------------------------------------------------+
| PHP Version 5 / Imagick |
+----------------------------------------------------------------------+
| Copyright (c) 2006-2013 Mikko Koppanen, Scott MacVicar |
| ImageMagick (c) ImageMagick Studio LLC |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Mikko Kopppanen <[email protected]> |
| Scott MacVicar <[email protected]> |
+----------------------------------------------------------------------+
*/
#include "php_imagick.h"
#include "php_imagick_defs.h"
#include "php_imagick_macros.h"
#include "php_imagick_helpers.h"
#include "php_imagick_file.h"
#if MagickLibVersion > 0x628
/* {{{ proto bool Imagick::pingImageFile(resource filehandle)
Query image information without reading the whole image to memory
*/
PHP_METHOD(Imagick, pingImageFile)
{
char *filename = NULL;
IM_LEN_TYPE filename_len;
php_imagick_object *intern;
zval *zstream;
php_stream *stream;
zend_bool result;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|s!", &zstream, &filename, &filename_len) == FAILURE)
{
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
#if PHP_VERSION_ID >= 70000
php_stream_from_zval(stream, zstream);
#else
php_stream_from_zval(stream, &zstream);
#endif
result = php_imagick_stream_handler(intern, stream, ImagickPingImageFile TSRMLS_CC);
if (result == 0) {
if (!EG(exception)) {
php_imagick_convert_imagick_exception(intern->magick_wand, "Unable to ping image from the filehandle" TSRMLS_CC);
}
RETURN_THROWS();
}
if (filename) {
MagickSetImageFilename(intern->magick_wand, filename);
MagickSetLastIterator(intern->magick_wand);
}
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool Imagick::pingImageBlob(string image )
Query image information without reading the whole image to memory
*/
PHP_METHOD(Imagick, pingImageBlob)
{
char *image_string;
IM_LEN_TYPE image_string_len;
MagickBooleanType status;
php_imagick_object *intern;
/* Parse parameters given to function */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &image_string, &image_string_len) == FAILURE) {
RETURN_THROWS();
}
if (image_string_len == 0) {
php_imagick_throw_exception(IMAGICK_CLASS, "Empty image string passed" TSRMLS_CC);
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
status = MagickPingImageBlob(intern->magick_wand, image_string, image_string_len);
/* No magick is going to happen */
if (status == MagickFalse) {
php_imagick_convert_imagick_exception(intern->magick_wand, "Unable to ping image blob" TSRMLS_CC);
RETURN_THROWS();
}
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool Imagick::vignetteImage(float blackPoint, float whitePoint, int x, int y )
Adds vignette filter to the image
*/
PHP_METHOD(Imagick, vignetteImage)
{
double black_point, white_point;
im_long x, y;
php_imagick_object *intern;
MagickBooleanType status;
/* Parse parameters given to function */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ddll", &black_point, &white_point, &x, &y) == FAILURE) {
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
IMAGICK_NOT_EMPTY(intern);
status = MagickVignetteImage(intern->magick_wand, black_point, white_point, x, y);
/* No magick is going to happen */
if (status == MagickFalse) {
php_imagick_convert_imagick_exception(intern->magick_wand, "Unable to apply vignette filter" TSRMLS_CC);
RETURN_THROWS();
}
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool Imagick::transposeImage()
Creates a vertical mirror image
*/
PHP_METHOD(Imagick, transposeImage)
{
php_imagick_object *intern;
MagickBooleanType status;
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
IMAGICK_NOT_EMPTY(intern);
status = MagickTransposeImage(intern->magick_wand);
/* No magick is going to happen */
if (status == MagickFalse) {
php_imagick_convert_imagick_exception(intern->magick_wand, "Unable to transpose image" TSRMLS_CC);
RETURN_THROWS();
}
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool Imagick::transverseImage()
Creates a horizontal mirror image
*/
PHP_METHOD(Imagick, transverseImage)
{
php_imagick_object *intern;
MagickBooleanType status;
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
IMAGICK_NOT_EMPTY(intern);
status = MagickTransverseImage(intern->magick_wand);
/* No magick is going to happen */
if (status == MagickFalse) {
php_imagick_convert_imagick_exception(intern->magick_wand, "Unable to transverse image" TSRMLS_CC);
RETURN_THROWS();
}
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool Imagick::adaptiveBlurImage(float radius, float sigma[, int channel] )
Adds adaptive blur filter to image
*/
PHP_METHOD(Imagick, adaptiveBlurImage)
{
double radius, sigma;
php_imagick_object *intern;
MagickBooleanType status;
im_long channel = IM_DEFAULT_CHANNEL;
/* Parse parameters given to function */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dd|l", &radius, &sigma, &channel) == FAILURE) {
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
IMAGICK_NOT_EMPTY(intern);
status = MagickAdaptiveBlurImageChannel(intern->magick_wand, channel, radius, sigma);
/* No magick is going to happen */
if (status == MagickFalse) {
php_imagick_convert_imagick_exception(intern->magick_wand, "Unable to adaptive blur image" TSRMLS_CC);
RETURN_THROWS();
}
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool Imagick::uniqueImageColors()
Discards all but one of any pixel color
*/
PHP_METHOD(Imagick, uniqueImageColors)
{
php_imagick_object *intern;
MagickBooleanType status;
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
IMAGICK_NOT_EMPTY(intern);
status = MagickUniqueImageColors(intern->magick_wand);
/* No magick is going to happen */
if (status == MagickFalse) {
php_imagick_convert_imagick_exception(intern->magick_wand, "Unable to get unique image colors" TSRMLS_CC);
RETURN_THROWS();
}
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool Imagick::contrastStretchImage(float black_point, float white_point[, int channel])
Enhances the contrast of a color image
*/
PHP_METHOD(Imagick, contrastStretchImage)
{
php_imagick_object *intern;
double black_point, white_point;
MagickBooleanType status;
im_long channel = IM_DEFAULT_CHANNEL;
/* Parse parameters given to function */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dd|l", &black_point, &white_point, &channel) == FAILURE) {
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
IMAGICK_NOT_EMPTY(intern);
status = MagickContrastStretchImageChannel(intern->magick_wand, channel, black_point, white_point);
/* No magick is going to happen */
if (status == MagickFalse) {
php_imagick_convert_imagick_exception(intern->magick_wand, "Unable to contrast strech image" TSRMLS_CC);
RETURN_THROWS();
}
RETURN_TRUE;
}
/* }}} */
#if !defined(MAGICKCORE_EXCLUDE_DEPRECATED)
#if MagickLibVersion < 0x700
/* {{{ proto int Imagick::getImageMatte()
Returns true if the image has a matte channel otherwise false
*/
PHP_METHOD(Imagick, getImageMatte)
{
php_imagick_object *intern;
MagickBooleanType matte;
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
IMAGICK_METHOD_DEPRECATED ("Imagick", "getImageMatte");
intern = Z_IMAGICK_P(getThis());
IMAGICK_NOT_EMPTY(intern);
matte = MagickGetImageMatte(intern->magick_wand);
if (matte == MagickTrue) {
RETURN_TRUE;
} else {
RETURN_FALSE;
}
}
/* }}} */
#endif //#if MagickLibVersion < 0x700
#endif
/* {{{ proto bool Imagick::setImageMatte(bool matte)
Sets the image matte channel
*/
PHP_METHOD(Imagick, setImageMatte)
{
php_imagick_object *intern;
zend_bool matte;
MagickBooleanType status;
/* Parse parameters given to function */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &matte) == FAILURE) {
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
IMAGICK_NOT_EMPTY(intern);
status = MagickSetImageMatte(intern->magick_wand, matte);
/* No magick is going to happen */
if (status == MagickFalse) {
php_imagick_convert_imagick_exception(intern->magick_wand, "Unable to set image matte" TSRMLS_CC);
RETURN_THROWS();
}
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool Imagick::adaptiveResizeImage(int width, int height[, bool bestfit[, bool legacy]]])
Adaptively resize image with data dependent triangulation
If legacy is true, the calculations are done with the small rounding bug that existed in
Imagick before 3.4.0. If false, the calculations should produce the same results as
ImageMagick CLI does.
*/
PHP_METHOD(Imagick, adaptiveResizeImage)
{
php_imagick_object *intern;
MagickBooleanType status;
im_long width, height, new_width, new_height;
zend_bool bestfit = 0;
zend_bool legacy = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll|bb", &width, &height, &bestfit, &legacy) == FAILURE) {
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
IMAGICK_NOT_EMPTY(intern);
if (!php_imagick_thumbnail_dimensions(intern->magick_wand, bestfit, width, height, &new_width, &new_height, legacy)) {
php_imagick_throw_exception(IMAGICK_CLASS, "Invalid image geometry" TSRMLS_CC);
RETURN_THROWS();
}
status = MagickAdaptiveResizeImage(intern->magick_wand, new_width, new_height);
if (status == MagickFalse) {
php_imagick_convert_imagick_exception(intern->magick_wand, "Unable to adaptive resize image" TSRMLS_CC);
RETURN_THROWS();
}
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool Imagick::sketchImage(float radius, float sigma, float angle)
Simulates a pencil sketch
*/
PHP_METHOD(Imagick, sketchImage)
{
double radius, sigma, angle;
MagickBooleanType status;
php_imagick_object *intern;
/* Parse parameters given to function */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ddd", &radius, &sigma, &angle) == FAILURE) {
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
IMAGICK_NOT_EMPTY(intern);
status = MagickSketchImage(intern->magick_wand, sigma, radius, angle);
/* No magick is going to happen */
if (status == MagickFalse) {
php_imagick_convert_imagick_exception(intern->magick_wand, "Unable to sketch image" TSRMLS_CC);
RETURN_THROWS();
}
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool Imagick::shadeImage(bool gray, float azimuth, float elevation)
Shines a distant light on an image
*/
PHP_METHOD(Imagick, shadeImage)
{
php_imagick_object *intern;
MagickBooleanType status;
double azimuth, elevation;
zend_bool gray;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "bdd", &gray, &azimuth, &elevation) == FAILURE) {
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
IMAGICK_NOT_EMPTY(intern);
status = MagickShadeImage(intern->magick_wand, gray, azimuth, elevation);
/* No magick is going to happen */
if (status == MagickFalse) {
php_imagick_convert_imagick_exception(intern->magick_wand, "Unable to shade image" TSRMLS_CC);
RETURN_THROWS();
}
RETURN_TRUE;
}
/* }}} */
/* {{{ proto int Imagick::getSizeOffset()
Returns the size offset associated with the Imagick object
*/
PHP_METHOD(Imagick, getSizeOffset)
{
php_imagick_object *intern;
ssize_t offset;
MagickBooleanType status;
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
status = MagickGetSizeOffset(intern->magick_wand, &offset);
if (status == MagickFalse) {
php_imagick_convert_imagick_exception(intern->magick_wand, "Unable to get size offset" TSRMLS_CC);
RETURN_THROWS();
}
RETVAL_LONG(offset);
}
/* }}} */
/* {{{ proto bool Imagick::setSizeOffset(int columns, int rows, int offset)
Sets the size and offset of the Imagick object
*/
PHP_METHOD(Imagick, setSizeOffset)
{
php_imagick_object *intern;
im_long columns, rows, offset;
MagickBooleanType status;
/* Parse parameters given to function */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", &columns, &rows, &offset) == FAILURE) {
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
status = MagickSetSizeOffset(intern->magick_wand, columns, rows, offset);
/* No magick is going to happen */
if (status == MagickFalse) {
php_imagick_convert_imagick_exception(intern->magick_wand, "Unable to set size offset" TSRMLS_CC);
RETURN_THROWS();
}
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool Imagick::adaptiveSharpenImage(float radius, float sigma[, int channel])
Adaptively sharpen image with data dependent triangulation
*/
PHP_METHOD(Imagick, adaptiveSharpenImage)
{
php_imagick_object *intern;
MagickBooleanType status;
double radius, sigma;
im_long channel = IM_DEFAULT_CHANNEL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dd|l", &radius, &sigma, &channel) == FAILURE) {
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
IMAGICK_NOT_EMPTY(intern);
status = MagickAdaptiveSharpenImageChannel(intern->magick_wand, channel, radius, sigma);
if (status == MagickFalse) {
php_imagick_convert_imagick_exception(intern->magick_wand, "Unable to adaptive sharpen image" TSRMLS_CC);
RETURN_THROWS();
}
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool Imagick::randomThresholdImage(float low, float high[, int channel])
Changes the value of individual pixels
*/
PHP_METHOD(Imagick, randomThresholdImage)
{
php_imagick_object *intern;
double low, high;
MagickBooleanType status;
im_long channel = IM_DEFAULT_CHANNEL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dd|l", &low, &high, &channel) == FAILURE) {
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
IMAGICK_NOT_EMPTY(intern);
status = MagickRandomThresholdImageChannel(intern->magick_wand, channel, low, high);
/* No magick is going to happen */
if (status == MagickFalse) {
php_imagick_convert_imagick_exception(intern->magick_wand, "Unable to random threshold image" TSRMLS_CC);
RETURN_THROWS();
}
RETURN_TRUE;
}
/* }}} */
/* {{{ proto string Imagick::roundCornersImage(float x_rounding, float y_rounding[, float stroke_width = 10[, float displace = 5[, float size_correction = -6]]] )
Rounds image corners
*/
PHP_METHOD(Imagick, roundCornersImage)
{
char *old_locale;
double x_rounding, y_rounding;
DrawingWand *draw;
MagickWand *mask_image;
PixelWand *color;
php_imagick_object *intern;
long image_width, image_height;
MagickBooleanType status;
double stroke_width = 10, displace = 5, correction = -6;
/* Parse parameters given to function */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dd|ddd", &x_rounding, &y_rounding, &stroke_width, &displace, &correction) == FAILURE) {
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
IMAGICK_NOT_EMPTY(intern);
image_width = MagickGetImageWidth(intern->magick_wand);
image_height = MagickGetImageHeight(intern->magick_wand);
if (!image_width || !image_height) {
php_imagick_throw_exception(IMAGICK_CLASS, "Unable to round corners on empty image" TSRMLS_CC);
RETURN_THROWS();
}
status = MagickSetImageMatte(intern->magick_wand, MagickTrue);
if (status == MagickFalse) {
php_imagick_throw_exception(IMAGICK_CLASS, "Unable to set image matte" TSRMLS_CC);
RETURN_THROWS();
}
/* Here we go.. */
color = NewPixelWand();
if (!color) {
php_imagick_throw_exception (IMAGICK_CLASS, "Failed to allocate PixelWand structure" TSRMLS_CC);
RETURN_THROWS();
}
draw = NewDrawingWand();
if (!draw) {
DestroyPixelWand (color);
php_imagick_throw_exception (IMAGICK_CLASS, "Failed to allocate DrawingWand structure" TSRMLS_CC);
RETURN_THROWS();
}
mask_image = NewMagickWand();
if (!mask_image) {
DestroyPixelWand (color);
DestroyDrawingWand (draw);
php_imagick_throw_exception (IMAGICK_CLASS, "Failed to allocate MagickWand structure" TSRMLS_CC);
RETURN_THROWS();
}
#define exit_cleanup() \
if (color != NULL) color = DestroyPixelWand(color); \
if (draw != NULL) draw = DestroyDrawingWand(draw); \
if (mask_image != NULL) mask_image = DestroyMagickWand(mask_image);
status = PixelSetColor(color, "transparent");
if (status == MagickFalse) {
exit_cleanup();
php_imagick_throw_exception(IMAGICK_CLASS, "Unable to set pixel color" TSRMLS_CC);
RETURN_THROWS();
}
status = MagickNewImage(mask_image, image_width, image_height, color);
if (status == MagickFalse) {
exit_cleanup();
php_imagick_throw_exception(IMAGICK_CLASS, "Unable to allocate mask image" TSRMLS_CC);
RETURN_THROWS();
}
MagickSetImageBackgroundColor(mask_image, color);
status = PixelSetColor(color, "white");
if (status == MagickFalse) {
exit_cleanup();
php_imagick_throw_exception(IMAGICK_CLASS, "Unable to set pixel color" TSRMLS_CC);
RETURN_THROWS();
}
DrawSetFillColor(draw, color);
status = PixelSetColor(color, "black");
if (status == MagickFalse) {
exit_cleanup();
php_imagick_throw_exception(IMAGICK_CLASS, "Unable to set pixel color" TSRMLS_CC);
RETURN_THROWS();
}
DrawSetStrokeColor(draw, color);
DrawSetStrokeWidth(draw, stroke_width);
DrawRoundRectangle(draw, displace, displace, image_width + correction, image_height + correction, x_rounding, y_rounding);
old_locale = php_imagick_set_locale (TSRMLS_C);
status = MagickDrawImage(mask_image, draw);
php_imagick_restore_locale (old_locale);
if (old_locale)
efree (old_locale);
if (status == MagickFalse) {
exit_cleanup();
php_imagick_throw_exception(IMAGICK_CLASS, "Unable to draw on image" TSRMLS_CC);
RETURN_THROWS();
}
#if MagickLibVersion >= 0x700
status = MagickCompositeImage(intern->magick_wand, mask_image, DstInCompositeOp, MagickTrue, 0, 0);
#else
status = MagickCompositeImage(intern->magick_wand, mask_image, DstInCompositeOp, 0, 0);
#endif
if (status == MagickFalse) {
exit_cleanup();
php_imagick_throw_exception(IMAGICK_CLASS, "Unable to composite image" TSRMLS_CC);
RETURN_THROWS();
}
exit_cleanup();
RETURN_TRUE;
#undef exit_cleanup
}
/* }}} */
/* {{{ proto int Imagick::getIteratorIndex()
Returns the index of the current active image
*/
PHP_METHOD(Imagick, getIteratorIndex)
{
MagickBooleanType status;
php_imagick_object *intern;
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
status = MagickGetIteratorIndex(intern->magick_wand);
ZVAL_LONG(return_value, (long)status);
}
/* }}} */
/* {{{ proto bool Imagick::setIteratorIndex(int index)
Sets the index of the Imagick object
*/
PHP_METHOD(Imagick, setIteratorIndex)
{
im_long index;
MagickBooleanType status;
php_imagick_object *intern;
/* Parse parameters given to function */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
status = MagickSetIteratorIndex(intern->magick_wand, index);
/* No magick is going to happen */
if (status == MagickFalse) {
php_imagick_convert_imagick_exception(intern->magick_wand, "Unable to set iterator index" TSRMLS_CC);
RETURN_THROWS();
}
intern->next_out_of_bound = 0;
RETURN_TRUE;
}
/* }}} */
#if MagickLibVersion < 0x700
/* {{{ proto Imagick Imagick::transformImage(string crop, string geometry )
Comfortability method for crop and resize
*/
PHP_METHOD(Imagick, transformImage)
{
char *crop, *geometry;
IM_LEN_TYPE crop_len, geometry_len;
MagickWand *transformed;
php_imagick_object *intern, *intern_return;
/* Parse parameters given to function */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &crop, &crop_len, &geometry, &geometry_len) == FAILURE) {
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
IMAGICK_NOT_EMPTY(intern);
transformed = MagickTransformImage(intern->magick_wand, crop, geometry);
if (!transformed) {
php_imagick_convert_imagick_exception(intern->magick_wand, "Transforming image failed" TSRMLS_CC);
RETURN_THROWS();
}
object_init_ex(return_value, php_imagick_sc_entry);
intern_return = Z_IMAGICK_P(return_value);
php_imagick_replace_magickwand(intern_return, transformed);
}
#endif //#if MagickLibVersion < 0x700
/* }}} */
#endif
#if MagickLibVersion > 0x630
#if MagickLibVersion < 0x700
/* {{{ proto bool Imagick::setImageOpacity(float opacity)
Sets the image to the specified opacity level
*/
PHP_METHOD(Imagick, setImageOpacity)
{
double opacity;
MagickBooleanType status;
php_imagick_object *intern;
/* Parse parameters given to function */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &opacity) == FAILURE) {
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
IMAGICK_NOT_EMPTY(intern);
status = MagickSetImageOpacity(intern->magick_wand, opacity);
/* No magick is going to happen */
if (status == MagickFalse) {
php_imagick_convert_imagick_exception(intern->magick_wand, "Unable to set image opacity" TSRMLS_CC);
RETURN_THROWS();
}
RETURN_TRUE;
}
/* }}} */
#endif
#if MagickLibVersion >= 0x700
/* {{{ proto bool Imagick::setImageAlpha(float alpha)
Sets the image to the specified alpha level
*/
PHP_METHOD(Imagick, setImageAlpha)
{
double alpha;
MagickBooleanType status;
php_imagick_object *intern;
/* Parse parameters given to function */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &alpha) == FAILURE) {
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
IMAGICK_NOT_EMPTY(intern);
status = MagickSetImageAlpha(intern->magick_wand, alpha);
/* No magick is going to happen */
if (status == MagickFalse) {
php_imagick_convert_imagick_exception(intern->magick_wand, "Unable to set image alpha" TSRMLS_CC);
RETURN_THROWS();
}
RETURN_TRUE;
}
/* }}} */
#endif
#if MagickLibVersion < 0x700
/* {{{ proto bool Imagick::orderedPosterizeImage(string threshold_map[, int CHANNEL])
Performs an ordered dither
*/
PHP_METHOD(Imagick, orderedPosterizeImage)
{
char *map;
IM_LEN_TYPE map_len;
MagickBooleanType status;
php_imagick_object *intern;
im_long channel = IM_DEFAULT_CHANNEL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &map, &map_len, &channel) == FAILURE) {
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
IMAGICK_NOT_EMPTY(intern);
status = MagickOrderedPosterizeImageChannel(intern->magick_wand, channel, map);
if (status == MagickFalse) {
php_imagick_convert_imagick_exception(intern->magick_wand, "Unable to posterize image" TSRMLS_CC);
RETURN_THROWS();
}
RETURN_TRUE;
}
/* }}} */
#endif //#if MagickLibVersion < 0x700
#endif //#if MagickLibVersion > 0x630
#if MagickLibVersion >= 0x700
/* {{{ proto bool Imagick::polaroidWithTextAndMethod(ImagickDraw properties, double angle, string text, int method)
Simulates a Polaroid picture with text and PixelInterpolateMethod
*/
PHP_METHOD(Imagick, polaroidWithTextAndMethod)
{
zval *objvar;
php_imagick_object *intern;
MagickBooleanType status;
php_imagickdraw_object *internd;
double angle;
char *caption;
IM_LEN_TYPE caption_len;
im_long method;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Odsl", &objvar, php_imagickdraw_sc_entry, &angle, &caption, &caption_len, &method) == FAILURE) {
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
IMAGICK_NOT_EMPTY(intern);
internd = Z_IMAGICKDRAW_P(objvar);
status = MagickPolaroidImage(
intern->magick_wand,
internd->drawing_wand,
caption,
angle,
method
);
/* No magick is going to happen */
if (status == MagickFalse) {
php_imagick_convert_imagick_exception(intern->magick_wand, "Unable to polaroidWithTextAndMethod image" TSRMLS_CC);
RETURN_THROWS();
}
RETURN_TRUE;
}
/* }}} */
#endif // MagickLibVersion >= 0x700
#if MagickLibVersion > 0x631
/* {{{ proto bool Imagick::polaroidImage(ImagickDraw properties, double angle )
Simulates a Polaroid picture
*/
PHP_METHOD(Imagick, polaroidImage)
{
zval *objvar;
php_imagick_object *intern;
MagickBooleanType status;
php_imagickdraw_object *internd;
double angle;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Od", &objvar, php_imagickdraw_sc_entry, &angle) == FAILURE) {
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
IMAGICK_NOT_EMPTY(intern);
internd = Z_IMAGICKDRAW_P(objvar);
#if MagickLibVersion >= 0x700
{
PixelInterpolateMethod method = BilinearInterpolatePixel;
char *caption = "TODO FIXME";
status = MagickPolaroidImage(intern->magick_wand,internd->drawing_wand,caption,angle,method);
}
#else
status = MagickPolaroidImage(intern->magick_wand, internd->drawing_wand, angle);
#endif
/* No magick is going to happen */
if (status == MagickFalse) {
php_imagick_convert_imagick_exception(intern->magick_wand, "Unable to polaroid image" TSRMLS_CC);
RETURN_THROWS();
}
RETURN_TRUE;
}
/* }}} */
/* {{{ proto string Imagick::getImageProperty(string name )
Eeturns a value associated with the specified property
*/
PHP_METHOD(Imagick, getImageProperty)
{
php_imagick_object *intern;
char *name, *value;
IM_LEN_TYPE name_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
IMAGICK_NOT_EMPTY(intern);
value = MagickGetImageProperty(intern->magick_wand, name);
if (value) {
IM_ZVAL_STRING(return_value, (char *)value);
IMAGICK_FREE_MAGICK_MEMORY(value);
return;
}
RETURN_FALSE;
}
/* }}} */
/* {{{ proto bool Imagick::setImageProperty(string name, string value )
returns a value associated with the specified property
*/
PHP_METHOD(Imagick, setImageProperty)
{
php_imagick_object *intern;
char *name, *value;
IM_LEN_TYPE name_len, value_len;
MagickBooleanType status;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &name_len, &value, &value_len) == FAILURE) {
RETURN_THROWS();
}
intern = Z_IMAGICK_P(getThis());
IMAGICK_NOT_EMPTY(intern);
status = MagickSetImageProperty(intern->magick_wand, name, value);
/* No magick is going to happen */
if (status == MagickFalse) {
php_imagick_convert_imagick_exception(intern->magick_wand, "Unable to set image property" TSRMLS_CC);
RETURN_THROWS();
}
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool Imagick::deleteImageProperty(string name)
Deletes an image property.
*/