php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
gd.c
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Authors: Rasmus Lerdorf <rasmus@php.net> |
14 | Stig Bakken <ssb@php.net> |
15 | Jim Winstead <jimw@php.net> |
16 +----------------------------------------------------------------------+
17 */
18
19/* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center,
20 Cold Spring Harbor Labs. */
21
22/* Note that there is no code from the gd package in this file */
23
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include "php.h"
29#include "php_ini.h"
30#include "ext/standard/head.h"
31#include <math.h>
32#include "SAPI.h"
33#include "php_gd.h"
35#include "ext/standard/info.h"
37#include "php_memory_streams.h"
39
40#ifdef HAVE_SYS_WAIT_H
41# include <sys/wait.h>
42#endif
43#ifdef HAVE_UNISTD_H
44# include <unistd.h>
45#endif
46#ifdef PHP_WIN32
47# include <io.h>
48# include <fcntl.h>
49# include <windows.h>
50# include <Winuser.h>
51# include <Wingdi.h>
52#endif
53
54#if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
55# include <X11/xpm.h>
56#endif
57
58#include "gd_compat.h"
59
60#ifdef HAVE_GD_BUNDLED
61# include "libgd/gd.h"
62# include "libgd/gd_errors.h"
63# include "libgd/gdfontt.h" /* 1 Tiny font */
64# include "libgd/gdfonts.h" /* 2 Small font */
65# include "libgd/gdfontmb.h" /* 3 Medium bold font */
66# include "libgd/gdfontl.h" /* 4 Large font */
67# include "libgd/gdfontg.h" /* 5 Giant font */
68#else
69# include <gd.h>
70# include <gd_errors.h>
71# include <gdfontt.h> /* 1 Tiny font */
72# include <gdfonts.h> /* 2 Small font */
73# include <gdfontmb.h> /* 3 Medium bold font */
74# include <gdfontl.h> /* 4 Large font */
75# include <gdfontg.h> /* 5 Giant font */
76#endif
77
78#if defined(HAVE_GD_FREETYPE) && defined(HAVE_GD_BUNDLED)
79# include <ft2build.h>
80# include FT_FREETYPE_H
81#endif
82
83#if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
84# include "X11/xpm.h"
85#endif
86
87#ifndef M_PI
88#define M_PI 3.14159265358979323846
89#endif
90
91/* don't used libgd constants, not used, so going to be removed */
92#define PHP_GD_FLIP_HORIZONTAL 1
93#define PHP_GD_FLIP_VERTICAL 2
94#define PHP_GD_FLIP_BOTH 3
95
96#ifdef HAVE_GD_FREETYPE
97static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int);
98#endif
99
100#include "gd_arginfo.h"
101
102/* as it is not really public, duplicate declaration here to avoid
103 pointless warnings */
104int overflow2(int a, int b);
105
106static void php_image_filter_negate(INTERNAL_FUNCTION_PARAMETERS);
107static void php_image_filter_grayscale(INTERNAL_FUNCTION_PARAMETERS);
108static void php_image_filter_brightness(INTERNAL_FUNCTION_PARAMETERS);
109static void php_image_filter_contrast(INTERNAL_FUNCTION_PARAMETERS);
110static void php_image_filter_colorize(INTERNAL_FUNCTION_PARAMETERS);
111static void php_image_filter_edgedetect(INTERNAL_FUNCTION_PARAMETERS);
112static void php_image_filter_emboss(INTERNAL_FUNCTION_PARAMETERS);
113static void php_image_filter_gaussian_blur(INTERNAL_FUNCTION_PARAMETERS);
114static void php_image_filter_selective_blur(INTERNAL_FUNCTION_PARAMETERS);
115static void php_image_filter_mean_removal(INTERNAL_FUNCTION_PARAMETERS);
116static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS);
117static void php_image_filter_pixelate(INTERNAL_FUNCTION_PARAMETERS);
118static void php_image_filter_scatter(INTERNAL_FUNCTION_PARAMETERS);
119
120/* End Section filters declarations */
121static gdImagePtr _php_image_create_from_string(zend_string *Data, const char *tn, gdImagePtr (*ioctx_func_p)(gdIOCtxPtr));
122static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, const char *tn, gdImagePtr (*func_p)(FILE *), gdImagePtr (*ioctx_func_p)(gdIOCtxPtr));
123static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, const char *tn);
124static gdIOCtx *create_stream_context(php_stream *stream, int close_stream);
125static gdIOCtx *create_output_context(zval *to_zval, uint32_t arg_num);
126static int _php_image_type(zend_string *data);
127
128/*********************************************************
129 *
130 * GD Object Representation
131 *
132 ********************************************************/
133
135
140
141static zend_object_handlers php_gd_image_object_handlers;
142
143static zend_function *php_gd_image_object_get_constructor(zend_object *object)
144{
145 zend_throw_error(NULL, "You cannot initialize a GdImage object except through helper functions");
146 return NULL;
147}
148
152
153static zend_always_inline php_gd_image_object* php_gd_exgdimage_from_zobj_p(zend_object* obj)
154{
155 return (php_gd_image_object *) ((char *) (obj) - XtOffsetOf(php_gd_image_object, std));
156}
157
163{
164 return php_gd_exgdimage_from_zobj_p(Z_OBJ_P(zp))->image;
165}
166
167
169{
170 size_t block_len = sizeof(php_gd_image_object) + zend_object_properties_size(class_type);
171 php_gd_image_object *intern = emalloc(block_len);
172 memset(intern, 0, block_len);
173
174 zend_object_std_init(&intern->std, class_type);
175 object_properties_init(&intern->std, class_type);
176
177 return &intern->std;
178}
179
180static void php_gd_image_object_free(zend_object *intern)
181{
182 php_gd_image_object *img_obj_ptr = php_gd_exgdimage_from_zobj_p(intern);
183 if (img_obj_ptr->image) {
184 gdImageDestroy(img_obj_ptr->image);
185 }
186 zend_object_std_dtor(intern);
187}
188
196{
198 php_gd_exgdimage_from_zobj_p(Z_OBJ_P(val))->image = image;
199}
200
201static void php_gd_object_minit_helper(void)
202{
203 gd_image_ce = register_class_GdImage();
205 gd_image_ce->default_object_handlers = &php_gd_image_object_handlers;
206
207 /* setting up the object handlers for the GdImage class */
208 memcpy(&php_gd_image_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
209 php_gd_image_object_handlers.clone_obj = NULL;
210 php_gd_image_object_handlers.free_obj = php_gd_image_object_free;
211 php_gd_image_object_handlers.get_constructor = php_gd_image_object_get_constructor;
212 php_gd_image_object_handlers.compare = zend_objects_not_comparable;
213 php_gd_image_object_handlers.offset = XtOffsetOf(php_gd_image_object, std);
214}
215
216static zend_class_entry *gd_font_ce = NULL;
217static zend_object_handlers php_gd_font_object_handlers;
218
223
224static php_gd_font_object *php_gd_font_object_from_zend_object(zend_object *zobj)
225{
226 return ((php_gd_font_object*)(zobj + 1)) - 1;
227}
228
229static zend_object *php_gd_font_object_to_zend_object(php_gd_font_object *obj)
230{
231 return ((zend_object*)(obj + 1)) - 1;
232}
233
234static zend_object *php_gd_font_object_create(zend_class_entry *ce)
235{
236 php_gd_font_object *obj = zend_object_alloc(sizeof(php_gd_font_object), ce);
237 zend_object *zobj = php_gd_font_object_to_zend_object(obj);
238
239 obj->font = NULL;
242 zobj->handlers = &php_gd_font_object_handlers;
243
244 return zobj;
245}
246
247static void php_gd_font_object_free(zend_object *zobj)
248{
249 php_gd_font_object *obj = php_gd_font_object_from_zend_object(zobj);
250
251 if (obj->font) {
252 if (obj->font->data) {
253 efree(obj->font->data);
254 }
255 efree(obj->font);
256 obj->font = NULL;
257 }
258
260}
261
262static zend_function *php_gd_font_object_get_constructor(zend_object *object)
263{
264 zend_throw_error(NULL, "You cannot initialize a GdFont object except through helper functions");
265 return NULL;
266}
267
268static void php_gd_font_minit_helper(void)
269{
270 gd_font_ce = register_class_GdFont();
271 gd_font_ce->create_object = php_gd_font_object_create;
272
273 /* setting up the object handlers for the GdFont class */
274 memcpy(&php_gd_font_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
275 php_gd_font_object_handlers.clone_obj = NULL;
276 php_gd_font_object_handlers.free_obj = php_gd_font_object_free;
277 php_gd_font_object_handlers.get_constructor = php_gd_font_object_get_constructor;
278 php_gd_font_object_handlers.offset = XtOffsetOf(php_gd_font_object, std);
279}
280
281/*********************************************************
282 *
283 * Extension Implementation
284 *
285 ********************************************************/
286
289 "gd",
290 ext_functions,
291 PHP_MINIT(gd),
292 PHP_MSHUTDOWN(gd),
293 NULL,
294 PHP_RSHUTDOWN(gd),
295 PHP_MINFO(gd),
296 PHP_GD_VERSION,
298};
299
300#ifdef COMPILE_DL_GD
302#endif
303
304/* {{{ PHP_INI_BEGIN */
306 PHP_INI_ENTRY_EX("gd.jpeg_ignore_warning", "1", PHP_INI_ALL, NULL, zend_ini_boolean_displayer_cb)
308/* }}} */
309
310/* {{{ php_gd_error_method */
311void php_gd_error_method(int type, const char *format, va_list args)
312{
313 switch (type) {
314#ifndef PHP_WIN32
315 case GD_DEBUG:
316 case GD_INFO:
317#endif
318 case GD_NOTICE:
319 type = E_NOTICE;
320 break;
321 case GD_WARNING:
322 type = E_WARNING;
323 break;
324 default:
325 type = E_ERROR;
326 }
327 php_verror(NULL, "", type, format, args);
328}
329/* }}} */
330
331/* {{{ PHP_MINIT_FUNCTION */
333{
334 php_gd_object_minit_helper();
335 php_gd_font_minit_helper();
336
337#if defined(HAVE_GD_FREETYPE) && defined(HAVE_GD_BUNDLED)
339#endif
341
343
344 register_gd_symbols(module_number);
345
346 return SUCCESS;
347}
348/* }}} */
349
350/* {{{ PHP_MSHUTDOWN_FUNCTION */
352{
353#if defined(HAVE_GD_FREETYPE) && defined(HAVE_GD_BUNDLED)
355#endif
357 return SUCCESS;
358}
359/* }}} */
360
361/* {{{ PHP_RSHUTDOWN_FUNCTION */
363{
364#ifdef HAVE_GD_FREETYPE
366#endif
367 return SUCCESS;
368}
369/* }}} */
370
371#ifdef HAVE_GD_BUNDLED
372#define PHP_GD_VERSION_STRING "bundled (2.1.0 compatible)"
373#else
374# define PHP_GD_VERSION_STRING GD_VERSION_STRING
375#endif
376
377/* {{{ PHP_MINFO_FUNCTION */
379{
381 php_info_print_table_row(2, "GD Support", "enabled");
382
383 /* need to use a PHPAPI function here because it is external module in windows */
384
385#ifdef HAVE_GD_BUNDLED
387#else
388 php_info_print_table_row(2, "GD headers Version", PHP_GD_VERSION_STRING);
389#ifdef HAVE_GD_LIBVERSION
390 php_info_print_table_row(2, "GD library Version", gdVersionString());
391#endif
392#endif
393
394#ifdef HAVE_GD_FREETYPE
395 php_info_print_table_row(2, "FreeType Support", "enabled");
396 php_info_print_table_row(2, "FreeType Linkage", "with freetype");
397#ifdef HAVE_GD_BUNDLED
398 {
399 char tmp[256];
400
401#ifdef FREETYPE_PATCH
402 snprintf(tmp, sizeof(tmp), "%d.%d.%d", FREETYPE_MAJOR, FREETYPE_MINOR, FREETYPE_PATCH);
403#elif defined(FREETYPE_MAJOR)
404 snprintf(tmp, sizeof(tmp), "%d.%d", FREETYPE_MAJOR, FREETYPE_MINOR);
405#else
406 snprintf(tmp, sizeof(tmp), "1.x");
407#endif
408 php_info_print_table_row(2, "FreeType Version", tmp);
409 }
410#endif
411#endif
412
413 php_info_print_table_row(2, "GIF Read Support", "enabled");
414 php_info_print_table_row(2, "GIF Create Support", "enabled");
415
416#ifdef HAVE_GD_JPG
417 {
418 php_info_print_table_row(2, "JPEG Support", "enabled");
419#ifdef HAVE_GD_BUNDLED
420 php_info_print_table_row(2, "libJPEG Version", gdJpegGetVersionString());
421#endif
422 }
423#endif
424
425#ifdef HAVE_GD_PNG
426 php_info_print_table_row(2, "PNG Support", "enabled");
427#ifdef HAVE_GD_BUNDLED
428 php_info_print_table_row(2, "libPNG Version", gdPngGetVersionString());
429#endif
430#endif
431 php_info_print_table_row(2, "WBMP Support", "enabled");
432#ifdef HAVE_GD_XPM
433 php_info_print_table_row(2, "XPM Support", "enabled");
434#ifdef HAVE_GD_BUNDLED
435 {
436 char tmp[12];
437 snprintf(tmp, sizeof(tmp), "%d", XpmLibraryVersion());
438 php_info_print_table_row(2, "libXpm Version", tmp);
439 }
440#endif
441#endif
442 php_info_print_table_row(2, "XBM Support", "enabled");
443#ifdef USE_GD_JISX0208
444 php_info_print_table_row(2, "JIS-mapped Japanese Font Support", "enabled");
445#endif
446#ifdef HAVE_GD_WEBP
447 php_info_print_table_row(2, "WebP Support", "enabled");
448#endif
449#ifdef HAVE_GD_BMP
450 php_info_print_table_row(2, "BMP Support", "enabled");
451#endif
452#ifdef HAVE_GD_AVIF
453 php_info_print_table_row(2, "AVIF Support", "enabled");
454#endif
455#ifdef HAVE_GD_TGA
456 php_info_print_table_row(2, "TGA Read Support", "enabled");
457#endif
460}
461/* }}} */
462
463/* {{{ */
465{
467
469
470 add_assoc_string(return_value, "GD Version", PHP_GD_VERSION_STRING);
471
472#ifdef HAVE_GD_FREETYPE
473 add_assoc_bool(return_value, "FreeType Support", 1);
474 add_assoc_string(return_value, "FreeType Linkage", "with freetype");
475#else
476 add_assoc_bool(return_value, "FreeType Support", 0);
477#endif
478 add_assoc_bool(return_value, "GIF Read Support", 1);
479 add_assoc_bool(return_value, "GIF Create Support", 1);
480#ifdef HAVE_GD_JPG
481 add_assoc_bool(return_value, "JPEG Support", 1);
482#else
483 add_assoc_bool(return_value, "JPEG Support", 0);
484#endif
485#ifdef HAVE_GD_PNG
486 add_assoc_bool(return_value, "PNG Support", 1);
487#else
488 add_assoc_bool(return_value, "PNG Support", 0);
489#endif
490 add_assoc_bool(return_value, "WBMP Support", 1);
491#ifdef HAVE_GD_XPM
492 add_assoc_bool(return_value, "XPM Support", 1);
493#else
494 add_assoc_bool(return_value, "XPM Support", 0);
495#endif
496 add_assoc_bool(return_value, "XBM Support", 1);
497#ifdef HAVE_GD_WEBP
498 add_assoc_bool(return_value, "WebP Support", 1);
499#else
500 add_assoc_bool(return_value, "WebP Support", 0);
501#endif
502#ifdef HAVE_GD_BMP
503 add_assoc_bool(return_value, "BMP Support", 1);
504#else
505 add_assoc_bool(return_value, "BMP Support", 0);
506#endif
507#ifdef HAVE_GD_AVIF
508 add_assoc_bool(return_value, "AVIF Support", 1);
509#else
510 add_assoc_bool(return_value, "AVIF Support", 0);
511#endif
512#ifdef HAVE_GD_TGA
513 add_assoc_bool(return_value, "TGA Read Support", 1);
514#else
515 add_assoc_bool(return_value, "TGA Read Support", 0);
516#endif
517#ifdef USE_GD_JISX0208
518 add_assoc_bool(return_value, "JIS-mapped Japanese Font Support", 1);
519#else
520 add_assoc_bool(return_value, "JIS-mapped Japanese Font Support", 0);
521#endif
522}
523/* }}} */
524
525#define FLIPWORD(a) (((a & 0xff000000) >> 24) | ((a & 0x00ff0000) >> 8) | ((a & 0x0000ff00) << 8) | ((a & 0x000000ff) << 24))
526
527/* {{{ Load a new font */
529{
531 int hdr_size = sizeof(gdFont) - sizeof(char *);
532 int body_size, n = 0, b, i, body_size_check;
533 gdFontPtr font;
534 php_stream *stream;
535
539
541 if (stream == NULL) {
543 }
544
545 /* Only supports a architecture-dependent binary dump format
546 * at the moment.
547 * The file format is like this on machines with 32-byte integers:
548 *
549 * byte 0-3: (int) number of characters in the font
550 * byte 4-7: (int) value of first character in the font (often 32, space)
551 * byte 8-11: (int) pixel width of each character
552 * byte 12-15: (int) pixel height of each character
553 * bytes 16-: (char) array with character data, one byte per pixel
554 * in each character, for a total of
555 * (nchars*width*height) bytes.
556 */
557 font = (gdFontPtr) emalloc(sizeof(gdFont));
558 b = 0;
559 while (b < hdr_size && (n = php_stream_read(stream, (char*)&font[b], hdr_size - b)) > 0) {
560 b += n;
561 }
562
563 if (n <= 0) {
564 efree(font);
565 if (php_stream_eof(stream)) {
566 php_error_docref(NULL, E_WARNING, "End of file while reading header");
567 } else {
568 php_error_docref(NULL, E_WARNING, "Error while reading header");
569 }
570 php_stream_close(stream);
572 }
573 i = php_stream_tell(stream);
574 php_stream_seek(stream, 0, SEEK_END);
575 body_size_check = php_stream_tell(stream) - hdr_size;
576 php_stream_seek(stream, i, SEEK_SET);
577
578 if (overflow2(font->nchars, font->h) || overflow2(font->nchars * font->h, font->w )) {
579 php_error_docref(NULL, E_WARNING, "Error reading font, invalid font header");
580 efree(font);
581 php_stream_close(stream);
583 }
584
585 body_size = font->w * font->h * font->nchars;
586 if (body_size != body_size_check) {
587 font->w = FLIPWORD(font->w);
588 font->h = FLIPWORD(font->h);
589 font->nchars = FLIPWORD(font->nchars);
590 if (overflow2(font->nchars, font->h) || overflow2(font->nchars * font->h, font->w )) {
591 php_error_docref(NULL, E_WARNING, "Error reading font, invalid font header");
592 efree(font);
593 php_stream_close(stream);
595 }
596 body_size = font->w * font->h * font->nchars;
597 }
598
599 if (body_size != body_size_check) {
600 php_error_docref(NULL, E_WARNING, "Error reading font");
601 efree(font);
602 php_stream_close(stream);
604 }
605
606 ZEND_ASSERT(body_size > 0);
607 font->data = emalloc(body_size);
608 b = 0;
609 while (b < body_size && (n = php_stream_read(stream, &font->data[b], body_size - b)) > 0) {
610 b += n;
611 }
612
613 if (n <= 0) {
614 efree(font->data);
615 efree(font);
616 if (php_stream_eof(stream)) {
617 php_error_docref(NULL, E_WARNING, "End of file while reading body");
618 } else {
619 php_error_docref(NULL, E_WARNING, "Error while reading body");
620 }
621 php_stream_close(stream);
623 }
624 php_stream_close(stream);
625
626 object_init_ex(return_value, gd_font_ce);
627 php_gd_font_object_from_zend_object(Z_OBJ_P(return_value))->font = font;
628}
629/* }}} */
630
631/* {{{ Set the line drawing styles for use with imageline and IMG_COLOR_STYLED. */
633{
634 zval *IM, *styles, *item;
635 gdImagePtr im;
636 int *stylearr;
637 int index = 0;
638 uint32_t num_styles;
639
642 Z_PARAM_ARRAY(styles)
644
646
647 num_styles = zend_hash_num_elements(Z_ARRVAL_P(styles));
648 if (num_styles == 0) {
651 }
652
653 /* copy the style values in the stylearr */
654 stylearr = safe_emalloc(sizeof(int), num_styles, 0);
655
656 ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(styles), item) {
657 stylearr[index++] = zval_get_long(item);
659
660 gdImageSetStyle(im, stylearr, index);
661
662 efree(stylearr);
663
665}
666/* }}} */
667
668/* {{{ Create a new true color image */
670{
671 zend_long x_size, y_size;
672 gdImagePtr im;
673
675 Z_PARAM_LONG(x_size)
676 Z_PARAM_LONG(y_size)
678
679 if (x_size <= 0 || x_size >= INT_MAX) {
680 zend_argument_value_error(1, "must be greater than 0");
682 }
683
684 if (y_size <= 0 || y_size >= INT_MAX) {
685 zend_argument_value_error(2, "must be greater than 0");
687 }
688
689 im = gdImageCreateTrueColor(x_size, y_size);
690
691 if (!im) {
693 }
694
696}
697/* }}} */
698
699/* {{{ return true if the image uses truecolor */
713/* }}} */
714
715/* {{{ Convert a true color image to a palette based image with a number of colors, optionally using dithering. */
717{
718 zval *IM;
719 bool dither;
720 zend_long ncolors;
721 gdImagePtr im;
722
725 Z_PARAM_BOOL(dither)
726 Z_PARAM_LONG(ncolors)
728
730
731 if (ncolors <= 0 || ZEND_LONG_INT_OVFL(ncolors)) {
732 zend_argument_value_error(3, "must be greater than 0 and less than %d", INT_MAX);
734 }
735
736 if (gdImageTrueColorToPalette(im, dither, (int)ncolors)) {
738 } else {
739 php_error_docref(NULL, E_WARNING, "Couldn't convert to palette");
741 }
742}
743/* }}} */
744
745/* {{{ Convert a palette based image to a true color image. */
763/* }}} */
764
765/* {{{ Makes the colors of the palette version of an image more closely match the true color version */
767{
768 zval *IM1, *IM2;
769 gdImagePtr im1, im2;
770 int result;
771
776
779
780 result = gdImageColorMatch(im1, im2);
781 switch (result) {
782 case -1:
783 zend_argument_value_error(1, "must be TrueColor");
785 break;
786 case -2:
787 zend_argument_value_error(2, "must be Palette");
789 break;
790 case -3:
791 zend_argument_value_error(2, "must be the same size as argument #1 ($im1)");
793 break;
794 case -4:
795 zend_argument_value_error(2, "must have at least one color");
797 break;
798 }
799
801}
802/* }}} */
803
804/* {{{ Set line thickness for drawing lines, ellipses, rectangles, polygons etc. */
822/* }}} */
823
824/* {{{ Draw an ellipse */
845/* }}} */
846
847/* {{{ Draw a filled partial ellipse */
849{
850 zval *IM;
851 zend_long cx, cy, w, h, ST, E, col, style;
852 gdImagePtr im;
853 int e, st;
854
857 Z_PARAM_LONG(cx)
858 Z_PARAM_LONG(cy)
859 Z_PARAM_LONG(w)
860 Z_PARAM_LONG(h)
861 Z_PARAM_LONG(ST)
862 Z_PARAM_LONG(E)
863 Z_PARAM_LONG(col)
864 Z_PARAM_LONG(style)
866
868
869 e = E;
870 if (e < 0) {
871 e %= 360;
872 }
873
874 st = ST;
875 if (st < 0) {
876 st %= 360;
877 }
878
879 gdImageFilledArc(im, cx, cy, w, h, st, e, col, style);
880
882}
883/* }}} */
884
885/* {{{ Turn alpha blending mode on or off for the given image */
887{
888 zval *IM;
889 bool blend;
890 gdImagePtr im;
891
894 Z_PARAM_BOOL(blend)
896
898
899 gdImageAlphaBlending(im, blend);
900
902}
903/* }}} */
904
905/* {{{ Include alpha channel to a saved image */
907{
908 zval *IM;
909 bool save;
910 gdImagePtr im;
911
914 Z_PARAM_BOOL(save)
916
918
919 gdImageSaveAlpha(im, save);
920
922}
923/* }}} */
924
925/* {{{ Set the alpha blending flag to use the bundled libgd layering effects */
943/* }}} */
944
945#define CHECK_RGBA_RANGE(component, name, argument_number) \
946 if (component < 0 || component > gd##name##Max) { \
947 zend_argument_value_error(argument_number, "must be between 0 and %d (inclusive)", gd##name##Max); \
948 RETURN_THROWS(); \
949 }
950
951/* {{{ Allocate a color with an alpha level. Works for true color and palette based images */
953{
954 zval *IM;
955 zend_long red, green, blue, alpha;
956 gdImagePtr im;
957 int ct = (-1);
958
961 Z_PARAM_LONG(red)
962 Z_PARAM_LONG(green)
963 Z_PARAM_LONG(blue)
964 Z_PARAM_LONG(alpha)
966
968
969 CHECK_RGBA_RANGE(red, Red, 2);
970 CHECK_RGBA_RANGE(green, Green, 3);
971 CHECK_RGBA_RANGE(blue, Blue, 4);
972 CHECK_RGBA_RANGE(alpha, Alpha, 5);
973
974 ct = gdImageColorAllocateAlpha(im, red, green, blue, alpha);
975 if (ct < 0) {
977 }
979}
980/* }}} */
981
982/* {{{ Resolve/Allocate a colour with an alpha level. Works for true colour and palette based images */
984{
985 zval *IM;
986 zend_long red, green, blue, alpha;
987 gdImagePtr im;
988
991 Z_PARAM_LONG(red)
992 Z_PARAM_LONG(green)
993 Z_PARAM_LONG(blue)
994 Z_PARAM_LONG(alpha)
996
998
999 CHECK_RGBA_RANGE(red, Red, 2);
1000 CHECK_RGBA_RANGE(green, Green, 3);
1001 CHECK_RGBA_RANGE(blue, Blue, 4);
1002 CHECK_RGBA_RANGE(alpha, Alpha, 5);
1003
1004 RETURN_LONG(gdImageColorResolveAlpha(im, red, green, blue, alpha));
1005}
1006/* }}} */
1007
1008/* {{{ Find the closest matching colour with alpha transparency */
1010{
1011 zval *IM;
1012 zend_long red, green, blue, alpha;
1013 gdImagePtr im;
1014
1017 Z_PARAM_LONG(red)
1018 Z_PARAM_LONG(green)
1019 Z_PARAM_LONG(blue)
1020 Z_PARAM_LONG(alpha)
1022
1024
1025 CHECK_RGBA_RANGE(red, Red, 2);
1026 CHECK_RGBA_RANGE(green, Green, 3);
1027 CHECK_RGBA_RANGE(blue, Blue, 4);
1028 CHECK_RGBA_RANGE(alpha, Alpha, 5);
1029
1030 RETURN_LONG(gdImageColorClosestAlpha(im, red, green, blue, alpha));
1031}
1032/* }}} */
1033
1034/* {{{ Find exact match for colour with transparency */
1036{
1037 zval *IM;
1038 zend_long red, green, blue, alpha;
1039 gdImagePtr im;
1040
1043 Z_PARAM_LONG(red)
1044 Z_PARAM_LONG(green)
1045 Z_PARAM_LONG(blue)
1046 Z_PARAM_LONG(alpha)
1048
1050
1051 CHECK_RGBA_RANGE(red, Red, 2);
1052 CHECK_RGBA_RANGE(green, Green, 3);
1053 CHECK_RGBA_RANGE(blue, Blue, 4);
1054 CHECK_RGBA_RANGE(alpha, Alpha, 5);
1055
1056 RETURN_LONG(gdImageColorExactAlpha(im, red, green, blue, alpha));
1057}
1058/* }}} */
1059
1060/* {{{ Copy and resize part of an image using resampling to help ensure clarity */
1062{
1063 zval *SIM, *DIM;
1064 zend_long SX, SY, SW, SH, DX, DY, DW, DH;
1065 gdImagePtr im_dst, im_src;
1066 int srcH, srcW, dstH, dstW, srcY, srcX, dstY, dstX;
1067
1071 Z_PARAM_LONG(DX)
1072 Z_PARAM_LONG(DY)
1073 Z_PARAM_LONG(SX)
1074 Z_PARAM_LONG(SY)
1075 Z_PARAM_LONG(DW)
1076 Z_PARAM_LONG(DH)
1080
1083
1084 srcX = SX;
1085 srcY = SY;
1086 srcH = SH;
1087 srcW = SW;
1088 dstX = DX;
1089 dstY = DY;
1090 dstH = DH;
1091 dstW = DW;
1092
1093 gdImageCopyResampled(im_dst, im_src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH);
1094
1096}
1097/* }}} */
1098
1099#ifdef PHP_WIN32
1100/* {{{ Grab a window or its client area using a windows handle (HWND property in COM instance) */
1102{
1103 HWND window;
1104 bool client_area = false;
1105 RECT rc = {0};
1106 int Width, Height;
1107 HDC hdc;
1108 HDC memDC;
1109 HBITMAP memBM;
1110 HBITMAP hOld;
1111 zend_long lwindow_handle;
1112 gdImagePtr im = NULL;
1113
1115 Z_PARAM_LONG(lwindow_handle)
1117 Z_PARAM_BOOL(client_area)
1119
1120 window = (HWND) lwindow_handle;
1121
1122 if (!IsWindow(window)) {
1123 php_error_docref(NULL, E_NOTICE, "Invalid window handle");
1125 }
1126
1127 hdc = GetDC(0);
1128
1129 if (client_area) {
1130 GetClientRect(window, &rc);
1131 Width = rc.right;
1132 Height = rc.bottom;
1133 } else {
1134 GetWindowRect(window, &rc);
1135 Width = rc.right - rc.left;
1136 Height = rc.bottom - rc.top;
1137 }
1138
1139 Width = (Width/4)*4;
1140
1141 memDC = CreateCompatibleDC(hdc);
1142 memBM = CreateCompatibleBitmap(hdc, Width, Height);
1143 hOld = (HBITMAP) SelectObject (memDC, memBM);
1144
1145 PrintWindow(window, memDC, (UINT) client_area);
1146
1147 im = gdImageCreateTrueColor(Width, Height);
1148 if (im) {
1149 int x,y;
1150 for (y=0; y <= Height; y++) {
1151 for (x=0; x <= Width; x++) {
1152 int c = GetPixel(memDC, x,y);
1153 gdImageSetPixel(im, x, y, gdTrueColor(GetRValue(c), GetGValue(c), GetBValue(c)));
1154 }
1155 }
1156 }
1157
1158 SelectObject(memDC,hOld);
1159 DeleteObject(memBM);
1160 DeleteDC(memDC);
1161 ReleaseDC( 0, hdc );
1162
1163 if (!im) {
1165 }
1166
1168}
1169/* }}} */
1170
1171/* {{{ Grab a screenshot */
1173{
1174 HWND window = GetDesktopWindow();
1175 RECT rc = {0};
1176 int Width, Height;
1177 HDC hdc;
1178 HDC memDC;
1179 HBITMAP memBM;
1180 HBITMAP hOld;
1181 gdImagePtr im;
1182 hdc = GetDC(0);
1183
1185
1186 if (!hdc) {
1188 }
1189
1190 GetWindowRect(window, &rc);
1191 Width = rc.right - rc.left;
1192 Height = rc.bottom - rc.top;
1193
1194 Width = (Width/4)*4;
1195
1196 memDC = CreateCompatibleDC(hdc);
1197 memBM = CreateCompatibleBitmap(hdc, Width, Height);
1198 hOld = (HBITMAP) SelectObject (memDC, memBM);
1199 BitBlt( memDC, 0, 0, Width, Height , hdc, rc.left, rc.top , SRCCOPY );
1200
1201 im = gdImageCreateTrueColor(Width, Height);
1202 if (im) {
1203 int x,y;
1204 for (y=0; y <= Height; y++) {
1205 for (x=0; x <= Width; x++) {
1206 int c = GetPixel(memDC, x,y);
1207 gdImageSetPixel(im, x, y, gdTrueColor(GetRValue(c), GetGValue(c), GetBValue(c)));
1208 }
1209 }
1210 }
1211
1212 SelectObject(memDC,hOld);
1213 DeleteObject(memBM);
1214 DeleteDC(memDC);
1215 ReleaseDC( 0, hdc );
1216
1217 if (!im) {
1219 }
1220
1222}
1223/* }}} */
1224#endif /* PHP_WIN32 */
1225
1226/* {{{ Rotate an image using a custom angle */
1228{
1229 zval *SIM;
1230 gdImagePtr im_dst, im_src;
1231 double degrees;
1233
1236 Z_PARAM_DOUBLE(degrees)
1239
1240 if (degrees < (double)(INT_MIN / 100) || degrees > (double)(INT_MAX / 100)) {
1241 zend_argument_value_error(2, "must be between %d and %d", (INT_MIN / 100), (INT_MAX / 100));
1242 RETURN_THROWS();
1243 }
1244
1246 im_dst = gdImageRotateInterpolated(im_src, (const float)degrees, color);
1247
1248 if (im_dst == NULL) {
1250 }
1251
1253}
1254/* }}} */
1255
1256/* {{{ Set the tile image to $tile when filling $image with the "IMG_COLOR_TILED" color */
1258{
1259 zval *IM, *TILE;
1260 gdImagePtr im, tile;
1261
1266
1269
1270 gdImageSetTile(im, tile);
1271
1273}
1274/* }}} */
1275
1276/* {{{ Set the brush image to $brush when filling $image with the "IMG_COLOR_BRUSHED" color */
1278{
1279 zval *IM, *TILE;
1280 gdImagePtr im, tile;
1281
1286
1289
1290 gdImageSetBrush(im, tile);
1291
1293}
1294/* }}} */
1295
1296/* {{{ Create a new image */
1298{
1299 zend_long x_size, y_size;
1300 gdImagePtr im;
1301
1303 Z_PARAM_LONG(x_size)
1304 Z_PARAM_LONG(y_size)
1306
1307 if (x_size <= 0 || x_size >= INT_MAX) {
1308 zend_argument_value_error(1, "must be greater than 0");
1309 RETURN_THROWS();
1310 }
1311
1312 if (y_size <= 0 || y_size >= INT_MAX) {
1313 zend_argument_value_error(2, "must be greater than 0");
1314 RETURN_THROWS();
1315 }
1316
1317 im = gdImageCreate(x_size, y_size);
1318
1319 if (!im) {
1321 }
1322
1324}
1325/* }}} */
1326
1327/* {{{ Return the types of images supported in a bitfield - 1=GIF, 2=JPEG, 4=PNG, 8=WBMP, 16=XPM, etc */
1329{
1330 int ret = 0;
1331 ret = PHP_IMG_GIF;
1332#ifdef HAVE_GD_JPG
1333 ret |= PHP_IMG_JPG;
1334#endif
1335#ifdef HAVE_GD_PNG
1336 ret |= PHP_IMG_PNG;
1337#endif
1338 ret |= PHP_IMG_WBMP;
1339#ifdef HAVE_GD_XPM
1340 ret |= PHP_IMG_XPM;
1341#endif
1342#ifdef HAVE_GD_WEBP
1343 ret |= PHP_IMG_WEBP;
1344#endif
1345#ifdef HAVE_GD_BMP
1346 ret |= PHP_IMG_BMP;
1347#endif
1348#ifdef HAVE_GD_TGA
1349 ret |= PHP_IMG_TGA;
1350#endif
1351#ifdef HAVE_GD_AVIF
1352 ret |= PHP_IMG_AVIF;
1353#endif
1354
1356
1358}
1359/* }}} */
1360
1361/* {{{ _php_ctx_getmbi */
1362
1363static int _php_ctx_getmbi(gdIOCtx *ctx)
1364{
1365 int i, mbi = 0;
1366
1367 do {
1368 i = (ctx->getC)(ctx);
1369 if (i < 0 || mbi > (INT_MAX >> 7)) {
1370 return -1;
1371 }
1372 mbi = (mbi << 7) | (i & 0x7f);
1373 } while (i & 0x80);
1374
1375 return mbi;
1376}
1377/* }}} */
1378
1379/* {{{ _php_image_type
1380 * Based on ext/standard/image.c
1381 */
1382static const char php_sig_gd2[3] = {'g', 'd', '2'};
1383
1384static int _php_image_type(zend_string *data)
1385{
1386 if (ZSTR_LEN(data) < 12) {
1387 /* Handle this the same way as an unknown image type. */
1388 return -1;
1389 }
1390
1391 if (!memcmp(ZSTR_VAL(data), php_sig_gd2, sizeof(php_sig_gd2))) {
1392 return PHP_GDIMG_TYPE_GD2;
1393 } else if (!memcmp(ZSTR_VAL(data), php_sig_jpg, sizeof(php_sig_jpg))) {
1394 return PHP_GDIMG_TYPE_JPG;
1395 } else if (!memcmp(ZSTR_VAL(data), php_sig_png, sizeof(php_sig_png))) {
1396 return PHP_GDIMG_TYPE_PNG;
1397 } else if (!memcmp(ZSTR_VAL(data), php_sig_gif, sizeof(php_sig_gif))) {
1398 return PHP_GDIMG_TYPE_GIF;
1399 } else if (!memcmp(ZSTR_VAL(data), php_sig_bmp, sizeof(php_sig_bmp))) {
1400 return PHP_GDIMG_TYPE_BMP;
1401 } else if(!memcmp(ZSTR_VAL(data), php_sig_riff, sizeof(php_sig_riff)) && !memcmp(ZSTR_VAL(data) + sizeof(php_sig_riff) + sizeof(uint32_t), php_sig_webp, sizeof(php_sig_webp))) {
1402 return PHP_GDIMG_TYPE_WEBP;
1403 }
1404
1406
1407 if (image_stream != NULL) {
1408 bool is_avif = php_is_image_avif(image_stream);
1409 php_stream_close(image_stream);
1410
1411 if (is_avif) {
1412 return PHP_GDIMG_TYPE_AVIF;
1413 }
1414 }
1415
1416 gdIOCtx *io_ctx;
1417 io_ctx = gdNewDynamicCtxEx(8, ZSTR_VAL(data), 0);
1418 if (io_ctx) {
1419 if (_php_ctx_getmbi(io_ctx) == 0 && _php_ctx_getmbi(io_ctx) >= 0) {
1420 io_ctx->gd_free(io_ctx);
1421 return PHP_GDIMG_TYPE_WBM;
1422 } else {
1423 io_ctx->gd_free(io_ctx);
1424 }
1425 }
1426
1427 return -1;
1428}
1429/* }}} */
1430
1431/* {{{ _php_image_create_from_string */
1432gdImagePtr _php_image_create_from_string(zend_string *data, const char *tn, gdImagePtr (*ioctx_func_p)(gdIOCtxPtr))
1433{
1434 gdImagePtr im;
1435 gdIOCtx *io_ctx;
1436
1438
1439 if (!io_ctx) {
1440 return NULL;
1441 }
1442
1443 im = (*ioctx_func_p)(io_ctx);
1444 if (!im) {
1445 php_error_docref(NULL, E_WARNING, "Passed data is not in \"%s\" format", tn);
1446 io_ctx->gd_free(io_ctx);
1447 return NULL;
1448 }
1449
1450 io_ctx->gd_free(io_ctx);
1451
1452 return im;
1453}
1454/* }}} */
1455
1456/* {{{ Create a new image from the image stream in the string */
1458{
1460 gdImagePtr im;
1461 int imtype;
1462
1466
1467 imtype = _php_image_type(data);
1468
1469 switch (imtype) {
1470 case PHP_GDIMG_TYPE_JPG:
1471#ifdef HAVE_GD_JPG
1472 im = _php_image_create_from_string(data, "JPEG", gdImageCreateFromJpegCtx);
1473#else
1474 php_error_docref(NULL, E_WARNING, "No JPEG support in this PHP build");
1476#endif
1477 break;
1478
1479 case PHP_GDIMG_TYPE_PNG:
1480#ifdef HAVE_GD_PNG
1481 im = _php_image_create_from_string(data, "PNG", gdImageCreateFromPngCtx);
1482#else
1483 php_error_docref(NULL, E_WARNING, "No PNG support in this PHP build");
1485#endif
1486 break;
1487
1488 case PHP_GDIMG_TYPE_GIF:
1489 im = _php_image_create_from_string(data, "GIF", gdImageCreateFromGifCtx);
1490 break;
1491
1492 case PHP_GDIMG_TYPE_WBM:
1493 im = _php_image_create_from_string(data, "WBMP", gdImageCreateFromWBMPCtx);
1494 break;
1495
1496 case PHP_GDIMG_TYPE_GD2:
1497 im = _php_image_create_from_string(data, "GD2", gdImageCreateFromGd2Ctx);
1498 break;
1499
1500 case PHP_GDIMG_TYPE_BMP:
1501 im = _php_image_create_from_string(data, "BMP", gdImageCreateFromBmpCtx);
1502 break;
1503
1504 case PHP_GDIMG_TYPE_WEBP:
1505#ifdef HAVE_GD_WEBP
1506 im = _php_image_create_from_string(data, "WEBP", gdImageCreateFromWebpCtx);
1507 break;
1508#else
1509 php_error_docref(NULL, E_WARNING, "No WEBP support in this PHP build");
1511#endif
1512
1513 case PHP_GDIMG_TYPE_AVIF:
1514#ifdef HAVE_GD_AVIF
1515 im = _php_image_create_from_string(data, "AVIF", gdImageCreateFromAvifCtx);
1516 break;
1517#else
1518 php_error_docref(NULL, E_WARNING, "No AVIF support in this PHP build");
1520#endif
1521
1522 default:
1523 php_error_docref(NULL, E_WARNING, "Data is not in a recognized format");
1525 }
1526
1527 if (!im) {
1528 php_error_docref(NULL, E_WARNING, "Couldn't create GD Image Stream out of Data");
1530 }
1531
1533}
1534/* }}} */
1535
1536/* {{{ _php_image_create_from */
1537static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, const char *tn, gdImagePtr (*func_p)(FILE *), gdImagePtr (*ioctx_func_p)(gdIOCtxPtr))
1538{
1539 char *file;
1540 size_t file_len;
1541 zend_long srcx, srcy, width, height;
1542 gdImagePtr im = NULL;
1543 php_stream *stream;
1544 FILE * fp = NULL;
1545#ifdef HAVE_GD_JPG
1546 long ignore_warning;
1547#endif
1548
1549 if (image_type == PHP_GDIMG_TYPE_GD2PART) {
1550 if (zend_parse_parameters(ZEND_NUM_ARGS(), "pllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) {
1551 RETURN_THROWS();
1552 }
1553
1554 if (width < 1) {
1555 zend_argument_value_error(4, "must be greater than or equal to 1");
1556 RETURN_THROWS();
1557 }
1558
1559 if (height < 1) {
1560 zend_argument_value_error(5, "must be greater than or equal to 1");
1561 RETURN_THROWS();
1562 }
1563
1564 } else {
1565 if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &file, &file_len) == FAILURE) {
1566 RETURN_THROWS();
1567 }
1568 }
1569
1570
1572 if (stream == NULL) {
1574 }
1575
1576 /* try and avoid allocating a FILE* if the stream is not naturally a FILE* */
1577 if (php_stream_is(stream, PHP_STREAM_IS_STDIO)) {
1578 if (FAILURE == php_stream_cast(stream, PHP_STREAM_AS_STDIO, (void**)&fp, REPORT_ERRORS)) {
1579 goto out_err;
1580 }
1581 } else if (ioctx_func_p || image_type == PHP_GDIMG_TYPE_GD2PART) {
1582 /* we can create an io context */
1583 gdIOCtx* io_ctx;
1584 zend_string *buff;
1585 char *pstr;
1586
1588
1589 if (!buff) {
1590 php_error_docref(NULL, E_WARNING,"Cannot read image data");
1591 goto out_err;
1592 }
1593
1594 /* needs to be malloc (persistent) - GD will free() it later */
1595 pstr = pestrndup(ZSTR_VAL(buff), ZSTR_LEN(buff), 1);
1596 io_ctx = gdNewDynamicCtxEx(ZSTR_LEN(buff), pstr, 0);
1597 if (!io_ctx) {
1598 pefree(pstr, 1);
1599 zend_string_release_ex(buff, 0);
1600 php_error_docref(NULL, E_WARNING,"Cannot allocate GD IO context");
1601 goto out_err;
1602 }
1603
1604 if (image_type == PHP_GDIMG_TYPE_GD2PART) {
1605 im = gdImageCreateFromGd2PartCtx(io_ctx, srcx, srcy, width, height);
1606 } else {
1607 im = (*ioctx_func_p)(io_ctx);
1608 }
1609 io_ctx->gd_free(io_ctx);
1610 pefree(pstr, 1);
1611 zend_string_release_ex(buff, 0);
1612 }
1613 else if (php_stream_can_cast(stream, PHP_STREAM_AS_STDIO)) {
1614 /* try and force the stream to be FILE* */
1616 goto out_err;
1617 }
1618 }
1619
1620 if (!im && fp) {
1621 switch (image_type) {
1622 case PHP_GDIMG_TYPE_GD2PART:
1623 im = gdImageCreateFromGd2Part(fp, srcx, srcy, width, height);
1624 break;
1625#ifdef HAVE_GD_XPM
1626 case PHP_GDIMG_TYPE_XPM:
1628 break;
1629#endif
1630
1631#ifdef HAVE_GD_JPG
1632 case PHP_GDIMG_TYPE_JPG:
1633 ignore_warning = INI_INT("gd.jpeg_ignore_warning");
1634 im = gdImageCreateFromJpegEx(fp, ignore_warning);
1635 break;
1636#endif
1637
1638 default:
1639 im = (*func_p)(fp);
1640 break;
1641 }
1642
1643 fflush(fp);
1644 }
1645
1646/* register_im: */
1647 if (im) {
1648 php_stream_close(stream);
1650 return;
1651 }
1652
1653 php_error_docref(NULL, E_WARNING, "\"%s\" is not a valid %s file", file, tn);
1654out_err:
1655 php_stream_close(stream);
1657
1658}
1659/* }}} */
1660
1661/* {{{ Create a new image from GIF file or URL */
1663{
1664 _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GIF, "GIF", gdImageCreateFromGif, gdImageCreateFromGifCtx);
1665}
1666/* }}} */
1667
1668#ifdef HAVE_GD_JPG
1669/* {{{ Create a new image from JPEG file or URL */
1671{
1672 _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG, "JPEG", gdImageCreateFromJpeg, gdImageCreateFromJpegCtx);
1673}
1674/* }}} */
1675#endif /* HAVE_GD_JPG */
1676
1677#ifdef HAVE_GD_PNG
1678/* {{{ Create a new image from PNG file or URL */
1680{
1681 _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImageCreateFromPng, gdImageCreateFromPngCtx);
1682}
1683/* }}} */
1684#endif /* HAVE_GD_PNG */
1685
1686#ifdef HAVE_GD_WEBP
1687/* {{{ Create a new image from WEBP file or URL */
1689{
1690 _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WEBP, "WEBP", gdImageCreateFromWebp, gdImageCreateFromWebpCtx);
1691}
1692/* }}} */
1693#endif /* HAVE_GD_WEBP */
1694
1695/* {{{ Create a new image from XBM file or URL */
1697{
1698 _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XBM, "XBM", gdImageCreateFromXbm, NULL);
1699}
1700/* }}} */
1701
1702#ifdef HAVE_GD_AVIF
1703/* {{{ Create a new image from AVIF file or URL */
1705{
1706 _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_AVIF, "AVIF", gdImageCreateFromAvif, gdImageCreateFromAvifCtx);
1707}
1708/* }}} */
1709#endif /* HAVE_GD_AVIF */
1710
1711#ifdef HAVE_GD_XPM
1712/* {{{ Create a new image from XPM file or URL */
1714{
1715 _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XPM, "XPM", NULL, NULL);
1716}
1717/* }}} */
1718#endif
1719
1720/* {{{ Create a new image from WBMP file or URL */
1722{
1723 _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, "WBMP", gdImageCreateFromWBMP, gdImageCreateFromWBMPCtx);
1724}
1725/* }}} */
1726
1727/* {{{ Create a new image from GD file or URL */
1729{
1730 _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD, "GD", gdImageCreateFromGd, gdImageCreateFromGdCtx);
1731}
1732/* }}} */
1733
1734/* {{{ Create a new image from GD2 file or URL */
1736{
1737 _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD2, "GD2", gdImageCreateFromGd2, gdImageCreateFromGd2Ctx);
1738}
1739/* }}} */
1740
1741/* {{{ Create a new image from a given part of GD2 file or URL */
1743{
1744 _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD2PART, "GD2", NULL, NULL);
1745}
1746/* }}} */
1747
1748#ifdef HAVE_GD_BMP
1749/* {{{ Create a new image from BMP file or URL */
1751{
1752 _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_BMP, "BMP", gdImageCreateFromBmp, gdImageCreateFromBmpCtx);
1753}
1754/* }}} */
1755#endif
1756
1757#ifdef HAVE_GD_TGA
1758/* {{{ Create a new image from TGA file or URL */
1760{
1761 _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_TGA, "TGA", gdImageCreateFromTga, gdImageCreateFromTgaCtx);
1762}
1763/* }}} */
1764#endif
1765
1766/* {{{ _php_image_output */
1767static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, const char *tn)
1768{
1769 zval *imgind;
1770 char *file = NULL;
1771 zend_long quality = 128, type = 1;
1772 gdImagePtr im;
1773 FILE *fp;
1774 size_t file_len = 0;
1775
1776 /* The quality parameter for gd2 stands for chunk size */
1777
1778 switch (image_type) {
1779 case PHP_GDIMG_TYPE_GD:
1780 if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|p!", &imgind, gd_image_ce, &file, &file_len) == FAILURE) {
1781 RETURN_THROWS();
1782 }
1783 break;
1784 case PHP_GDIMG_TYPE_GD2:
1785 if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|p!ll", &imgind, gd_image_ce, &file, &file_len, &quality, &type) == FAILURE) {
1786 RETURN_THROWS();
1787 }
1788 break;
1790 }
1791
1792 /* quality must fit in an int */
1793 if (quality < INT_MIN || quality > INT_MAX) {
1794 php_error_docref(NULL, E_WARNING, "Argument #3 ($chunk_size) must be between %d and %d", INT_MIN, INT_MAX);
1796 }
1797
1799
1800 if (file_len) {
1801 PHP_GD_CHECK_OPEN_BASEDIR(file, "Invalid filename");
1802
1803 fp = VCWD_FOPEN(file, "wb");
1804 if (!fp) {
1805 php_error_docref(NULL, E_WARNING, "Unable to open \"%s\" for writing", file);
1807 }
1808
1809 switch (image_type) {
1810 case PHP_GDIMG_TYPE_GD:
1811 gdImageGd(im, fp);
1812 break;
1813 case PHP_GDIMG_TYPE_GD2:
1814 if (quality == -1) {
1815 quality = 128;
1816 }
1817 gdImageGd2(im, fp, quality, type);
1818 break;
1820 }
1821 fflush(fp);
1822 fclose(fp);
1823 } else {
1824 int b;
1825 FILE *tmp;
1826 char buf[4096];
1827 zend_string *path;
1828
1829 tmp = php_open_temporary_file(NULL, NULL, &path);
1830 if (tmp == NULL) {
1831 php_error_docref(NULL, E_WARNING, "Unable to open temporary file");
1833 }
1834
1835 switch (image_type) {
1836 case PHP_GDIMG_TYPE_GD:
1837 gdImageGd(im, tmp);
1838 break;
1839 case PHP_GDIMG_TYPE_GD2:
1840 if (quality == -1) {
1841 quality = 128;
1842 }
1843 gdImageGd2(im, tmp, quality, type);
1844 break;
1846 }
1847
1848 fseek(tmp, 0, SEEK_SET);
1849
1850 while ((b = fread(buf, 1, sizeof(buf), tmp)) > 0) {
1851 php_write(buf, b);
1852 }
1853
1854 fclose(tmp);
1855 VCWD_UNLINK((const char *)ZSTR_VAL(path)); /* make sure that the temporary file is removed */
1856 zend_string_release_ex(path, 0);
1857 }
1859}
1860/* }}} */
1861
1862/* {{{ Output XBM image to browser or file */
1864{
1865 zval *imgind;
1866 char *file = NULL;
1867 size_t file_len = 0;
1868 zend_long foreground_color;
1869 bool foreground_color_is_null = true;
1870 gdImagePtr im;
1871 int i;
1872 gdIOCtx *ctx = NULL;
1873 php_stream *stream;
1874
1877 Z_PARAM_PATH_OR_NULL(file, file_len)
1879 Z_PARAM_LONG_OR_NULL(foreground_color, foreground_color_is_null)
1881
1883
1884 if (file != NULL) {
1886 if (stream == NULL) {
1888 }
1889
1890 ctx = create_stream_context(stream, 1);
1891 } else {
1892 ctx = create_output_context(NULL, 0);
1893 }
1894
1895 if (foreground_color_is_null) {
1896 for (i = 0; i < gdImageColorsTotal(im); i++) {
1897 if (!gdImageRed(im, i) && !gdImageGreen(im, i) && !gdImageBlue(im, i)) {
1898 break;
1899 }
1900 }
1901
1902 foreground_color = i;
1903 }
1904
1905 gdImageXbmCtx(im, file ? file : "", (int) foreground_color, ctx);
1906
1907 ctx->gd_free(ctx);
1908
1910}
1911/* }}} */
1912
1913/* {{{ Output GIF image to browser or file */
1915{
1916 zval *imgind;
1917 gdImagePtr im;
1918 gdIOCtx *ctx;
1919 zval *to_zval = NULL;
1920
1921 if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|z!", &imgind, gd_image_ce, &to_zval) == FAILURE) {
1922 RETURN_THROWS();
1923 }
1924
1926
1927 ctx = create_output_context(to_zval, 2);
1928 if (!ctx) {
1930 }
1931
1932 gdImageGifCtx(im, ctx);
1933
1934 ctx->gd_free(ctx);
1935
1937}
1938/* }}} */
1939
1940#ifdef HAVE_GD_PNG
1941/* {{{ Output PNG image to browser or file */
1943{
1944 zval *imgind;
1945 zend_long quality = -1, basefilter = -1;
1946 gdImagePtr im;
1947 gdIOCtx *ctx;
1948 zval *to_zval = NULL;
1949
1950 if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|z!ll", &imgind, gd_image_ce, &to_zval, &quality, &basefilter) == FAILURE) {
1951 RETURN_THROWS();
1952 }
1953
1955
1956 ctx = create_output_context(to_zval, 2);
1957 if (!ctx) {
1959 }
1960
1961 if (quality < -1 || quality > 9) {
1962 zend_argument_value_error(3, "must be between -1 and 9");
1963 ctx->gd_free(ctx);
1964 RETURN_THROWS();
1965 }
1966
1967#ifdef HAVE_GD_BUNDLED
1968 gdImagePngCtxEx(im, ctx, (int) quality, (int) basefilter);
1969#else
1970 gdImagePngCtxEx(im, ctx, (int) quality);
1971#endif
1972
1973 ctx->gd_free(ctx);
1974
1976}
1977/* }}} */
1978#endif /* HAVE_GD_PNG */
1979
1980#ifdef HAVE_GD_WEBP
1981/* {{{ Output WEBP image to browser or file */
1983{
1984 zval *imgind;
1985 zend_long quality = -1;
1986 gdImagePtr im;
1987 gdIOCtx *ctx;
1988 zval *to_zval = NULL;
1989
1990 if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|z!l", &imgind, gd_image_ce, &to_zval, &quality) == FAILURE) {
1991 RETURN_THROWS();
1992 }
1993
1995
1996 ctx = create_output_context(to_zval, 2);
1997 if (!ctx) {
1999 }
2000
2001 if (quality < -1) {
2002 zend_argument_value_error(3, "must be greater than or equal to -1");
2003 ctx->gd_free(ctx);
2004 RETURN_THROWS();
2005 }
2006
2007 gdImageWebpCtx(im, ctx, (int) quality);
2008
2009 ctx->gd_free(ctx);
2010
2012}
2013/* }}} */
2014#endif /* HAVE_GD_WEBP */
2015
2016#ifdef HAVE_GD_AVIF
2017/* {{{ Output AVIF image to browser or file */
2019{
2020 zval *imgind;
2021 zend_long quality = -1, speed = -1;
2022 gdImagePtr im;
2023 gdIOCtx *ctx;
2024 zval *to_zval = NULL;
2025
2026 if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|z!ll", &imgind, gd_image_ce, &to_zval, &quality, &speed) == FAILURE) {
2027 RETURN_THROWS();
2028 }
2029
2031
2032 ctx = create_output_context(to_zval, 2);
2033 if (!ctx) {
2035 }
2036
2037 if (quality < -1 || quality > 100) {
2038 zend_argument_value_error(3, "must be between -1 and 100");
2039 ctx->gd_free(ctx);
2040 RETURN_THROWS();
2041 }
2042
2043 if (speed < -1 || speed > 10) {
2044 zend_argument_value_error(4, "must be between -1 and 10");
2045 ctx->gd_free(ctx);
2046 RETURN_THROWS();
2047 } else if (speed == -1) {
2048 speed = 6;
2049 }
2050
2051 gdImageAvifCtx(im, ctx, (int) quality, (int) speed);
2052
2053 ctx->gd_free(ctx);
2054
2056}
2057/* }}} */
2058#endif /* HAVE_GD_AVIF */
2059
2060#ifdef HAVE_GD_JPG
2061/* {{{ Output JPEG image to browser or file */
2063{
2064 zval *imgind;
2065 zend_long quality = -1;
2066 gdImagePtr im;
2067 gdIOCtx *ctx;
2068 zval *to_zval = NULL;
2069
2070 if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|z!l", &imgind, gd_image_ce, &to_zval, &quality) == FAILURE) {
2071 RETURN_THROWS();
2072 }
2073
2075
2076 ctx = create_output_context(to_zval, 2);
2077 if (!ctx) {
2079 }
2080
2081 if (quality < -1 || quality > 100) {
2082 zend_argument_value_error(3, "must be at between -1 and 100");
2083 ctx->gd_free(ctx);
2084 RETURN_THROWS();
2085 }
2086
2087 gdImageJpegCtx(im, ctx, (int) quality);
2088
2089 ctx->gd_free(ctx);
2090
2092}
2093/* }}} */
2094#endif /* HAVE_GD_JPG */
2095
2096/* {{{ Output WBMP image to browser or file */
2098{
2099 zval *imgind;
2100 zend_long foreground_color;
2101 bool foreground_color_is_null = true;
2102 gdImagePtr im;
2103 int i;
2104 gdIOCtx *ctx;
2105 zval *to_zval = NULL;
2106
2110 Z_PARAM_ZVAL_OR_NULL(to_zval)
2111 Z_PARAM_LONG_OR_NULL(foreground_color, foreground_color_is_null)
2113
2115
2116 ctx = create_output_context(to_zval, 2);
2117 if (!ctx) {
2119 }
2120
2121 if (foreground_color_is_null) {
2122 for (i = 0; i < gdImageColorsTotal(im); i++) {
2123 if (!gdImageRed(im, i) && !gdImageGreen(im, i) && !gdImageBlue(im, i)) {
2124 break;
2125 }
2126 }
2127
2128 foreground_color = i;
2129 }
2130
2131 gdImageWBMPCtx(im, foreground_color, ctx);
2132
2133 ctx->gd_free(ctx);
2134
2136}
2137/* }}} */
2138
2139/* {{{ Output GD image to browser or file */
2141{
2142 _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD, "GD");
2143}
2144/* }}} */
2145
2146/* {{{ Output GD2 image to browser or file */
2148{
2149 _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD2, "GD2");
2150}
2151/* }}} */
2152
2153#ifdef HAVE_GD_BMP
2154/* {{{ Output BMP image to browser or file */
2156{
2157 zval *imgind;
2158 bool compressed = true;
2159 gdImagePtr im;
2160 gdIOCtx *ctx;
2161 zval *to_zval = NULL;
2162
2166 Z_PARAM_ZVAL_OR_NULL(to_zval)
2167 Z_PARAM_BOOL(compressed)
2169
2171
2172 ctx = create_output_context(to_zval, 2);
2173 if (!ctx) {
2175 }
2176
2177 gdImageBmpCtx(im, ctx, (int) compressed);
2178
2179 ctx->gd_free(ctx);
2180
2182}
2183/* }}} */
2184#endif
2185
2186/* {{{ Destroy an image - No effect as of PHP 8.0 */
2188{
2189 /* This function used to free the resource, as resources are no longer used, it does nothing */
2190 zval *IM;
2191
2195
2197}
2198/* }}} */
2199
2200/* {{{ Allocate a color for an image */
2202{
2203 zval *IM;
2204 zend_long red, green, blue;
2205 gdImagePtr im;
2206 int ct = -1;
2207
2210 Z_PARAM_LONG(red)
2211 Z_PARAM_LONG(green)
2212 Z_PARAM_LONG(blue)
2214
2216
2217 CHECK_RGBA_RANGE(red, Red, 2);
2218 CHECK_RGBA_RANGE(green, Green, 3);
2219 CHECK_RGBA_RANGE(blue, Blue, 4);
2220
2221 ct = gdImageColorAllocate(im, red, green, blue);
2222 if (ct < 0) {
2224 }
2225 RETURN_LONG(ct);
2226}
2227/* }}} */
2228
2229/* {{{ Copy the palette from the src image onto the dst image */
2231{
2232 zval *dstim, *srcim;
2233 gdImagePtr dst, src;
2234
2239
2242
2243 gdImagePaletteCopy(dst, src);
2244}
2245/* }}} */
2246
2247/* {{{ Get the index of the color of a pixel */
2249{
2250 zval *IM;
2251 zend_long x, y;
2252 gdImagePtr im;
2253
2256 Z_PARAM_LONG(x)
2257 Z_PARAM_LONG(y)
2259
2261
2262 if (gdImageTrueColor(im)) {
2263 if (im->tpixels && gdImageBoundsSafe(im, x, y)) {
2265 } else {
2266 php_error_docref(NULL, E_NOTICE, "" ZEND_LONG_FMT "," ZEND_LONG_FMT " is out of bounds", x, y);
2268 }
2269 } else {
2270 if (im->pixels && gdImageBoundsSafe(im, x, y)) {
2271 RETURN_LONG(im->pixels[y][x]);
2272 } else {
2273 php_error_docref(NULL, E_NOTICE, "" ZEND_LONG_FMT "," ZEND_LONG_FMT " is out of bounds", x, y);
2275 }
2276 }
2277}
2278/* }}} */
2279
2280/* {{{ Get the index of the closest color to the specified color */
2282{
2283 zval *IM;
2284 zend_long red, green, blue;
2285 gdImagePtr im;
2286
2289 Z_PARAM_LONG(red)
2290 Z_PARAM_LONG(green)
2291 Z_PARAM_LONG(blue)
2293
2295
2296 CHECK_RGBA_RANGE(red, Red, 2);
2297 CHECK_RGBA_RANGE(green, Green, 3);
2298 CHECK_RGBA_RANGE(blue, Blue, 4);
2299
2300 RETURN_LONG(gdImageColorClosest(im, red, green, blue));
2301}
2302/* }}} */
2303
2304/* {{{ Get the index of the color which has the hue, white and blackness nearest to the given color */
2306{
2307 zval *IM;
2308 zend_long red, green, blue;
2309 gdImagePtr im;
2310
2313 Z_PARAM_LONG(red)
2314 Z_PARAM_LONG(green)
2315 Z_PARAM_LONG(blue)
2317
2319
2320 CHECK_RGBA_RANGE(red, Red, 2);
2321 CHECK_RGBA_RANGE(green, Green, 3);
2322 CHECK_RGBA_RANGE(blue, Blue, 4);
2323
2324 RETURN_LONG(gdImageColorClosestHWB(im, red, green, blue));
2325}
2326/* }}} */
2327
2328/* {{{ De-allocate a color for an image */
2330{
2331 zval *IM;
2332 zend_long index;
2333 int col;
2334 gdImagePtr im;
2335
2338 Z_PARAM_LONG(index)
2340
2342
2343 /* We can return right away for a truecolor image as deallocating colours is meaningless here */
2344 if (gdImageTrueColor(im)) {
2346 }
2347
2348 col = index;
2349
2350 if (col >= 0 && col < gdImageColorsTotal(im)) {
2351 gdImageColorDeallocate(im, col);
2353 } else {
2354 zend_argument_value_error(2, "must be between 0 and %d", gdImageColorsTotal(im));
2355 RETURN_THROWS();
2356 }
2357}
2358/* }}} */
2359
2360/* {{{ Get the index of the specified color or its closest possible alternative */
2362{
2363 zval *IM;
2364 zend_long red, green, blue;
2365 gdImagePtr im;
2366
2369 Z_PARAM_LONG(red)
2370 Z_PARAM_LONG(green)
2371 Z_PARAM_LONG(blue)
2373
2375
2376 CHECK_RGBA_RANGE(red, Red, 2);
2377 CHECK_RGBA_RANGE(green, Green, 3);
2378 CHECK_RGBA_RANGE(blue, Blue, 4);
2379
2380 RETURN_LONG(gdImageColorResolve(im, red, green, blue));
2381}
2382/* }}} */
2383
2384/* {{{ Get the index of the specified color */
2386{
2387 zval *IM;
2388 zend_long red, green, blue;
2389 gdImagePtr im;
2390
2393 Z_PARAM_LONG(red)
2394 Z_PARAM_LONG(green)
2395 Z_PARAM_LONG(blue)
2397
2399
2400 CHECK_RGBA_RANGE(red, Red, 2);
2401 CHECK_RGBA_RANGE(green, Green, 3);
2402 CHECK_RGBA_RANGE(blue, Blue, 4);
2403
2404 RETURN_LONG(gdImageColorExact(im, red, green, blue));
2405}
2406/* }}} */
2407
2408/* {{{ Set the color for the specified palette index */
2410{
2411 zval *IM;
2412 zend_long color, red, green, blue, alpha = 0;
2413 int col;
2414 gdImagePtr im;
2415
2419 Z_PARAM_LONG(red)
2420 Z_PARAM_LONG(green)
2421 Z_PARAM_LONG(blue)
2423 Z_PARAM_LONG(alpha)
2425
2427
2428 CHECK_RGBA_RANGE(red, Red, 3);
2429 CHECK_RGBA_RANGE(green, Green, 4);
2430 CHECK_RGBA_RANGE(blue, Blue, 5);
2431 CHECK_RGBA_RANGE(alpha, Alpha, 6);
2432
2433 col = color;
2434
2435 if (col >= 0 && col < gdImageColorsTotal(im)) {
2436 im->red[col] = red;
2437 im->green[col] = green;
2438 im->blue[col] = blue;
2439 im->alpha[col] = alpha;
2440 } else {
2442 }
2443}
2444/* }}} */
2445
2446/* {{{ Get the colors for an index */
2448{
2449 zval *IM;
2450 zend_long index;
2451 int col;
2452 gdImagePtr im;
2453
2456 Z_PARAM_LONG(index)
2458
2460
2461 col = index;
2462
2463 if ((col >= 0 && gdImageTrueColor(im)) || (!gdImageTrueColor(im) && col >= 0 && col < gdImageColorsTotal(im))) {
2465
2466 add_assoc_long(return_value,"red", gdImageRed(im,col));
2467 add_assoc_long(return_value,"green", gdImageGreen(im,col));
2468 add_assoc_long(return_value,"blue", gdImageBlue(im,col));
2469 add_assoc_long(return_value,"alpha", gdImageAlpha(im,col));
2470 } else {
2471 zend_argument_value_error(2, "is out of range");
2472 RETURN_THROWS();
2473 }
2474}
2475/* }}} */
2476
2477/* {{{ Apply a gamma correction to a GD image */
2479{
2480 zval *IM;
2481 gdImagePtr im;
2482 int i;
2483 double input, output, gamma;
2484
2487 Z_PARAM_DOUBLE(input)
2488 Z_PARAM_DOUBLE(output)
2490
2491 if (input <= 0.0) {
2492 zend_argument_value_error(2, "must be greater than 0");
2493 RETURN_THROWS();
2494 }
2495
2496 if (output <= 0.0) {
2497 zend_argument_value_error(3, "must be greater than 0");
2498 RETURN_THROWS();
2499 }
2500
2501 gamma = input / output;
2502
2504
2505 if (gdImageTrueColor(im)) {
2506 int x, y, c;
2507
2508 for (y = 0; y < gdImageSY(im); y++) {
2509 for (x = 0; x < gdImageSX(im); x++) {
2510 c = gdImageGetPixel(im, x, y);
2511 gdImageSetPixel(im, x, y,
2513 (int) ((pow((gdTrueColorGetRed(c) / 255.0), gamma) * 255) + .5),
2514 (int) ((pow((gdTrueColorGetGreen(c) / 255.0), gamma) * 255) + .5),
2515 (int) ((pow((gdTrueColorGetBlue(c) / 255.0), gamma) * 255) + .5),
2517 )
2518 );
2519 }
2520 }
2522 }
2523
2524 for (i = 0; i < gdImageColorsTotal(im); i++) {
2525 im->red[i] = (int)((pow((im->red[i] / 255.0), gamma) * 255) + .5);
2526 im->green[i] = (int)((pow((im->green[i] / 255.0), gamma) * 255) + .5);
2527 im->blue[i] = (int)((pow((im->blue[i] / 255.0), gamma) * 255) + .5);
2528 }
2529
2531}
2532/* }}} */
2533
2534/* {{{ Set a single pixel */
2536{
2537 zval *IM;
2538 zend_long x, y, col;
2539 gdImagePtr im;
2540
2543 Z_PARAM_LONG(x)
2544 Z_PARAM_LONG(y)
2545 Z_PARAM_LONG(col)
2547
2549
2550 gdImageSetPixel(im, x, y, col);
2552}
2553/* }}} */
2554
2555/* {{{ Draw a line */
2557{
2558 zval *IM;
2559 zend_long x1, y1, x2, y2, col;
2560 gdImagePtr im;
2561
2564 Z_PARAM_LONG(x1)
2565 Z_PARAM_LONG(y1)
2566 Z_PARAM_LONG(x2)
2567 Z_PARAM_LONG(y2)
2568 Z_PARAM_LONG(col)
2570
2571
2573
2574 if (im->AA) {
2575 gdImageSetAntiAliased(im, col);
2576 col = gdAntiAliased;
2577 }
2578 gdImageLine(im, x1, y1, x2, y2, col);
2580}
2581/* }}} */
2582
2583/* {{{ Draw a dashed line */
2585{
2586 zval *IM;
2587 zend_long x1, y1, x2, y2, col;
2588 gdImagePtr im;
2589
2592 Z_PARAM_LONG(x1)
2593 Z_PARAM_LONG(y1)
2594 Z_PARAM_LONG(x2)
2595 Z_PARAM_LONG(y2)
2596 Z_PARAM_LONG(col)
2598
2600
2601 gdImageDashedLine(im, x1, y1, x2, y2, col);
2603}
2604/* }}} */
2605
2606/* {{{ Draw a rectangle */
2608{
2609 zval *IM;
2610 zend_long x1, y1, x2, y2, col;
2611 gdImagePtr im;
2612
2615 Z_PARAM_LONG(x1)
2616 Z_PARAM_LONG(y1)
2617 Z_PARAM_LONG(x2)
2618 Z_PARAM_LONG(y2)
2619 Z_PARAM_LONG(col)
2621
2623
2624 gdImageRectangle(im, x1, y1, x2, y2, col);
2626}
2627/* }}} */
2628
2629/* {{{ Draw a filled rectangle */
2631{
2632 zval *IM;
2633 zend_long x1, y1, x2, y2, col;
2634 gdImagePtr im;
2635
2638 Z_PARAM_LONG(x1)
2639 Z_PARAM_LONG(y1)
2640 Z_PARAM_LONG(x2)
2641 Z_PARAM_LONG(y2)
2642 Z_PARAM_LONG(col)
2644
2646 gdImageFilledRectangle(im, x1, y1, x2, y2, col);
2648}
2649/* }}} */
2650
2651/* {{{ Draw a partial ellipse */
2653{
2654 zval *IM;
2655 zend_long cx, cy, w, h, ST, E, col;
2656 gdImagePtr im;
2657 int e, st;
2658
2661 Z_PARAM_LONG(cx)
2662 Z_PARAM_LONG(cy)
2663 Z_PARAM_LONG(w)
2664 Z_PARAM_LONG(h)
2665 Z_PARAM_LONG(ST)
2666 Z_PARAM_LONG(E)
2667 Z_PARAM_LONG(col)
2669
2671
2672 e = E;
2673 if (e < 0) {
2674 e %= 360;
2675 }
2676
2677 st = ST;
2678 if (st < 0) {
2679 st %= 360;
2680 }
2681
2682 gdImageArc(im, cx, cy, w, h, st, e, col);
2684}
2685/* }}} */
2686
2687/* {{{ Draw an ellipse */
2689{
2690 zval *IM;
2691 zend_long cx, cy, w, h, color;
2692 gdImagePtr im;
2693
2696 Z_PARAM_LONG(cx)
2697 Z_PARAM_LONG(cy)
2698 Z_PARAM_LONG(w)
2699 Z_PARAM_LONG(h)
2702
2704
2705 gdImageEllipse(im, cx, cy, w, h, color);
2707}
2708/* }}} */
2709
2710/* {{{ Flood fill to specific color */
2712{
2713 zval *IM;
2714 zend_long x, y, border, col;
2715 gdImagePtr im;
2716
2719 Z_PARAM_LONG(x)
2720 Z_PARAM_LONG(y)
2721 Z_PARAM_LONG(border)
2722 Z_PARAM_LONG(col)
2724
2726
2727 gdImageFillToBorder(im, x, y, border, col);
2729}
2730/* }}} */
2731
2732/* {{{ Flood fill */
2734{
2735 zval *IM;
2736 zend_long x, y, col;
2737 gdImagePtr im;
2738
2741 Z_PARAM_LONG(x)
2742 Z_PARAM_LONG(y)
2743 Z_PARAM_LONG(col)
2745
2747
2748 gdImageFill(im, x, y, col);
2750}
2751/* }}} */
2752
2753/* {{{ Find out the number of colors in an image's palette */
2767/* }}} */
2768
2769/* {{{ Define a color as transparent */
2771{
2772 zval *IM;
2773 zend_long COL = 0;
2774 bool COL_IS_NULL = true;
2775 gdImagePtr im;
2776
2780 Z_PARAM_LONG_OR_NULL(COL, COL_IS_NULL)
2782
2784
2785 if (!COL_IS_NULL) {
2786 gdImageColorTransparent(im, COL);
2787 }
2788
2790}
2791/* }}} */
2792
2793/* {{{ Enable or disable interlace */
2795{
2796 zval *IM;
2797 bool INT = false;
2798 bool INT_IS_NULL = true;
2799 gdImagePtr im;
2800
2804 Z_PARAM_BOOL_OR_NULL(INT, INT_IS_NULL)
2806
2808
2809 if (!INT_IS_NULL) {
2810 gdImageInterlace(im, INT);
2811 }
2812
2814}
2815/* }}} */
2816
2817/* {{{ php_imagepolygon
2818 arg = -1 open polygon
2819 arg = 0 normal polygon
2820 arg = 1 filled polygon */
2821/* im, points, num_points, col */
2822static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled)
2823{
2824 zval *IM, *POINTS;
2825 zend_long NPOINTS, COL;
2826 bool COL_IS_NULL = true;
2827 zval *var = NULL;
2828 gdImagePtr im;
2829 gdPointPtr points;
2830 int npoints, col, nelem, i;
2831
2834 Z_PARAM_ARRAY(POINTS)
2835 Z_PARAM_LONG(NPOINTS)
2837 Z_PARAM_LONG_OR_NULL(COL, COL_IS_NULL)
2839
2840 if (COL_IS_NULL) {
2841 COL = NPOINTS;
2842 NPOINTS = zend_hash_num_elements(Z_ARRVAL_P(POINTS));
2843 if (NPOINTS % 2 != 0) {
2844 zend_argument_value_error(2, "must have an even number of elements");
2845 RETURN_THROWS();
2846 }
2847 NPOINTS /= 2;
2848 } else {
2849 php_error_docref(NULL, E_DEPRECATED, "Using the $num_points parameter is deprecated");
2850 }
2851
2853
2854 npoints = NPOINTS;
2855 col = COL;
2856
2857 nelem = zend_hash_num_elements(Z_ARRVAL_P(POINTS));
2858 if (npoints < 3) {
2859 zend_argument_value_error(3, "must be greater than or equal to 3");
2860 RETURN_THROWS();
2861 }
2862
2863 if (nelem < npoints * 2) {
2864 zend_value_error("Trying to use %d points in array with only %d points", npoints, nelem/2);
2865 RETURN_THROWS();
2866 }
2867
2868 points = (gdPointPtr) safe_emalloc(npoints, sizeof(gdPoint), 0);
2869
2870 for (i = 0; i < npoints; i++) {
2871 if ((var = zend_hash_index_find(Z_ARRVAL_P(POINTS), (i * 2))) != NULL) {
2872 points[i].x = zval_get_long(var);
2873 }
2874 if ((var = zend_hash_index_find(Z_ARRVAL_P(POINTS), (i * 2) + 1)) != NULL) {
2875 points[i].y = zval_get_long(var);
2876 }
2877 }
2878
2879 if (im->AA) {
2880 gdImageSetAntiAliased(im, col);
2881 col = gdAntiAliased;
2882 }
2883 switch (filled) {
2884 case -1:
2885 gdImageOpenPolygon(im, points, npoints, col);
2886 break;
2887 case 0:
2888 gdImagePolygon(im, points, npoints, col);
2889 break;
2890 case 1:
2891 gdImageFilledPolygon(im, points, npoints, col);
2892 break;
2893 }
2894
2895 efree(points);
2897}
2898/* }}} */
2899
2900/* {{{ Draw a polygon */
2902{
2903 php_imagepolygon(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
2904}
2905/* }}} */
2906
2907/* {{{ Draw a polygon */
2909{
2910 php_imagepolygon(INTERNAL_FUNCTION_PARAM_PASSTHRU, -1);
2911}
2912/* }}} */
2913
2914/* {{{ Draw a filled polygon */
2919/* }}} */
2920
2921/* {{{ php_find_gd_font */
2922static gdFontPtr php_find_gd_font(zend_object *font_obj, zend_long font_int)
2923{
2924 if (font_obj) {
2925 return php_gd_font_object_from_zend_object(font_obj)->font;
2926 }
2927
2928 switch (font_int) {
2929 case 1: return gdFontTiny;
2930 case 2: return gdFontSmall;
2931 case 3: return gdFontMediumBold;
2932 case 4: return gdFontLarge;
2933 case 5: return gdFontGiant;
2934 }
2935
2936 return font_int < 1 ? gdFontTiny : gdFontGiant;
2937}
2938/* }}} */
2939
2940/* {{{ php_imagefontsize
2941 * arg = 0 ImageFontWidth
2942 * arg = 1 ImageFontHeight
2943 */
2944static void php_imagefontsize(INTERNAL_FUNCTION_PARAMETERS, int arg)
2945{
2946 zend_object *font_obj = NULL;
2947 zend_long font_int = 0;
2948 gdFontPtr font;
2949
2951 Z_PARAM_OBJ_OF_CLASS_OR_LONG(font_obj, gd_font_ce, font_int)
2953
2954 font = php_find_gd_font(font_obj, font_int);
2955 RETURN_LONG(arg ? font->h : font->w);
2956}
2957/* }}} */
2958
2959/* {{{ Get font width */
2961{
2962 php_imagefontsize(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
2963}
2964/* }}} */
2965
2966/* {{{ Get font height */
2968{
2969 php_imagefontsize(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
2970}
2971/* }}} */
2972
2973/* {{{ php_gdimagecharup
2974 * workaround for a bug in gd 1.2 */
2975static void php_gdimagecharup(gdImagePtr im, gdFontPtr f, int x, int y, int c, int color)
2976{
2977 int cx, cy, px, py, fline;
2978 cx = 0;
2979 cy = 0;
2980
2981 if ((c < f->offset) || (c >= (f->offset + f->nchars))) {
2982 return;
2983 }
2984
2985 fline = (c - f->offset) * f->h * f->w;
2986 for (py = y; (py > (y - f->w)); py--) {
2987 for (px = x; (px < (x + f->h)); px++) {
2988 if (f->data[fline + cy * f->w + cx]) {
2989 gdImageSetPixel(im, px, py, color);
2990 }
2991 cy++;
2992 }
2993 cy = 0;
2994 cx++;
2995 }
2996}
2997/* }}} */
2998
2999/* {{{ php_imagechar
3000 * arg = 0 ImageChar
3001 * arg = 1 ImageCharUp
3002 * arg = 2 ImageString
3003 * arg = 3 ImageStringUp
3004 */
3005static void php_imagechar(INTERNAL_FUNCTION_PARAMETERS, int mode)
3006{
3007 zval *IM;
3008 zend_long X, Y, COL;
3009 zend_string *C;
3010 gdImagePtr im;
3011 int ch = 0, col, x, y, i, l = 0;
3012 unsigned char *str = NULL;
3013 zend_object *font_obj = NULL;
3014 zend_long font_int = 0;
3015
3018 Z_PARAM_OBJ_OF_CLASS_OR_LONG(font_obj, gd_font_ce, font_int)
3020 Z_PARAM_LONG(Y)
3021 Z_PARAM_STR(C)
3022 Z_PARAM_LONG(COL)
3024
3026
3027 col = COL;
3028
3029 if (mode < 2) {
3030 ch = (int)((unsigned char)*ZSTR_VAL(C));
3031 } else {
3032 str = (unsigned char *) estrndup(ZSTR_VAL(C), ZSTR_LEN(C));
3033 l = strlen((char *)str);
3034 }
3035
3036 y = Y;
3037 x = X;
3038
3039 gdFontPtr font = php_find_gd_font(font_obj, font_int);
3040
3041 switch (mode) {
3042 case 0:
3043 gdImageChar(im, font, x, y, ch, col);
3044 break;
3045 case 1:
3046 php_gdimagecharup(im, font, x, y, ch, col);
3047 break;
3048 case 2:
3049 for (i = 0; (i < l); i++) {
3050 gdImageChar(im, font, x, y, (int) ((unsigned char) str[i]), col);
3051 x += font->w;
3052 }
3053 break;
3054 case 3: {
3055 for (i = 0; (i < l); i++) {
3056 /* php_gdimagecharup(im, font, x, y, (int) str[i], col); */
3057 gdImageCharUp(im, font, x, y, (int) str[i], col);
3058 y -= font->w;
3059 }
3060 break;
3061 }
3062 }
3063 if (str) {
3064 efree(str);
3065 }
3067}
3068/* }}} */
3069
3070/* {{{ Draw a character */
3072{
3073 php_imagechar(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
3074}
3075/* }}} */
3076
3077/* {{{ Draw a character rotated 90 degrees counter-clockwise */
3079{
3080 php_imagechar(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
3081}
3082/* }}} */
3083
3084/* {{{ Draw a string horizontally */
3086{
3087 php_imagechar(INTERNAL_FUNCTION_PARAM_PASSTHRU, 2);
3088}
3089/* }}} */
3090
3091/* {{{ Draw a string vertically - rotated 90 degrees counter-clockwise */
3096/* }}} */
3097
3098/* {{{ Copy part of an image */
3100{
3101 zval *SIM, *DIM;
3102 zend_long SX, SY, SW, SH, DX, DY;
3103 gdImagePtr im_dst, im_src;
3104 int srcH, srcW, srcY, srcX, dstY, dstX;
3105
3109 Z_PARAM_LONG(DX)
3110 Z_PARAM_LONG(DY)
3111 Z_PARAM_LONG(SX)
3112 Z_PARAM_LONG(SY)
3116
3119
3120 srcX = SX;
3121 srcY = SY;
3122 srcH = SH;
3123 srcW = SW;
3124 dstX = DX;
3125 dstY = DY;
3126
3127 gdImageCopy(im_dst, im_src, dstX, dstY, srcX, srcY, srcW, srcH);
3129}
3130/* }}} */
3131
3132/* {{{ Merge one part of an image with another */
3134{
3135 zval *SIM, *DIM;
3136 zend_long SX, SY, SW, SH, DX, DY, PCT;
3137 gdImagePtr im_dst, im_src;
3138 int srcH, srcW, srcY, srcX, dstY, dstX, pct;
3139
3143 Z_PARAM_LONG(DX)
3144 Z_PARAM_LONG(DY)
3145 Z_PARAM_LONG(SX)
3146 Z_PARAM_LONG(SY)
3149 Z_PARAM_LONG(PCT)
3151
3154
3155 srcX = SX;
3156 srcY = SY;
3157 srcH = SH;
3158 srcW = SW;
3159 dstX = DX;
3160 dstY = DY;
3161 pct = PCT;
3162
3163 gdImageCopyMerge(im_dst, im_src, dstX, dstY, srcX, srcY, srcW, srcH, pct);
3165}
3166/* }}} */
3167
3168/* {{{ Merge one part of an image with another */
3170{
3171 zval *SIM, *DIM;
3172 zend_long SX, SY, SW, SH, DX, DY, PCT;
3173 gdImagePtr im_dst, im_src;
3174 int srcH, srcW, srcY, srcX, dstY, dstX, pct;
3175
3179 Z_PARAM_LONG(DX)
3180 Z_PARAM_LONG(DY)
3181 Z_PARAM_LONG(SX)
3182 Z_PARAM_LONG(SY)
3185 Z_PARAM_LONG(PCT)
3187
3190
3191 srcX = SX;
3192 srcY = SY;
3193 srcH = SH;
3194 srcW = SW;
3195 dstX = DX;
3196 dstY = DY;
3197 pct = PCT;
3198
3199 gdImageCopyMergeGray(im_dst, im_src, dstX, dstY, srcX, srcY, srcW, srcH, pct);
3201}
3202/* }}} */
3203
3204/* {{{ Copy and resize part of an image */
3206{
3207 zval *SIM, *DIM;
3208 zend_long SX, SY, SW, SH, DX, DY, DW, DH;
3209 gdImagePtr im_dst, im_src;
3210 int srcH, srcW, dstH, dstW, srcY, srcX, dstY, dstX;
3211
3215 Z_PARAM_LONG(DX)
3216 Z_PARAM_LONG(DY)
3217 Z_PARAM_LONG(SX)
3218 Z_PARAM_LONG(SY)
3219 Z_PARAM_LONG(DW)
3220 Z_PARAM_LONG(DH)
3224
3227
3228 srcX = SX;
3229 srcY = SY;
3230 srcH = SH;
3231 srcW = SW;
3232 dstX = DX;
3233 dstY = DY;
3234 dstH = DH;
3235 dstW = DW;
3236
3237 if (dstW <= 0) {
3238 zend_argument_value_error(7, "must be greater than 0");
3239 RETURN_THROWS();
3240 }
3241
3242 if (dstH <= 0) {
3243 zend_argument_value_error(8, "must be greater than 0");
3244 RETURN_THROWS();
3245 }
3246
3247 if (srcW <= 0) {
3248 zend_argument_value_error(9, "must be greater than 0");
3249 RETURN_THROWS();
3250 }
3251
3252 if (srcH <= 0) {
3253 zend_argument_value_error(10, "must be greater than 0");
3254 RETURN_THROWS();
3255 }
3256
3257 gdImageCopyResized(im_dst, im_src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH);
3259}
3260/* }}} */
3261
3262/* {{{ Get image width */
3276/* }}} */
3277
3278/* {{{ Get image height */
3292/* }}} */
3293
3294/* {{{ Set the clipping rectangle. */
3296{
3297 zval *im_zval;
3298 gdImagePtr im;
3299 zend_long x1, y1, x2, y2;
3300
3303 Z_PARAM_LONG(x1)
3304 Z_PARAM_LONG(y1)
3305 Z_PARAM_LONG(x2)
3306 Z_PARAM_LONG(y2)
3308
3310
3311 gdImageSetClip(im, x1, y1, x2, y2);
3313}
3314/* }}} */
3315
3316/* {{{ Get the clipping rectangle. */
3318{
3319 zval *im_zval;
3320 gdImagePtr im;
3321 int x1, y1, x2, y2;
3322
3326
3328
3329 gdImageGetClip(im, &x1, &y1, &x2, &y2);
3330
3336}
3337/* }}} */
3338
3339#define TTFTEXT_DRAW 0
3340#define TTFTEXT_BBOX 1
3341
3342#ifdef HAVE_GD_FREETYPE
3343/* {{{ Give the bounding box of a text using fonts via freetype2 */
3345{
3346 php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_BBOX);
3347}
3348/* }}} */
3349
3350/* {{{ Write text to the image using fonts via freetype2 */
3352{
3353 php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_DRAW);
3354}
3355/* }}} */
3356
3357/* {{{ php_imagettftext_common */
3358static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode)
3359{
3360 zval *IM, *EXT = NULL;
3361 gdImagePtr im=NULL;
3362 zend_long col = -1, x = 0, y = 0;
3363 size_t str_len, fontname_len;
3364 int i, brect[8];
3365 double ptsize, angle;
3366 char *str = NULL, *fontname = NULL;
3367 char *error = NULL;
3368 gdFTStringExtra strex = {0};
3369
3370 if (mode == TTFTEXT_BBOX) {
3371 if (zend_parse_parameters(ZEND_NUM_ARGS(), "ddss|a", &ptsize, &angle, &fontname, &fontname_len, &str, &str_len, &EXT) == FAILURE) {
3372 RETURN_THROWS();
3373 }
3374 } else {
3375 if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oddlllss|a", &IM, gd_image_ce, &ptsize, &angle, &x, &y, &col, &fontname, &fontname_len, &str, &str_len, &EXT) == FAILURE) {
3376 RETURN_THROWS();
3377 }
3379 }
3380
3381 // FT_F26Dot6 is a signed long alias
3382 if (ptsize < (double)LONG_MIN / 64 || ptsize > (double)LONG_MAX / 64) {
3383 zend_argument_value_error(2, "must be between " ZEND_LONG_FMT " and " ZEND_LONG_FMT, (zend_long)((double)LONG_MIN / 64), (zend_long)((double)LONG_MAX / 64));
3384 RETURN_THROWS();
3385 }
3386
3387 if (UNEXPECTED(!zend_finite(ptsize))) {
3388 zend_argument_value_error(2, "must be finite");
3389 RETURN_THROWS();
3390 }
3391
3392 /* convert angle to radians */
3393 angle = angle * (M_PI/180);
3394
3395 if (EXT) { /* parse extended info */
3396 zval *item;
3398
3399 /* walk the assoc array */
3400 if (!HT_IS_PACKED(Z_ARRVAL_P(EXT))) {
3402 if (key == NULL) {
3403 continue;
3404 }
3405 if (zend_string_equals_literal(key, "linespacing")) {
3406 strex.flags |= gdFTEX_LINESPACE;
3407 strex.linespacing = zval_get_double(item);
3408 }
3410 }
3411 }
3412
3413#ifdef VIRTUAL_DIR
3414 {
3415 char tmp_font_path[MAXPATHLEN];
3416
3417 if (!VCWD_REALPATH(fontname, tmp_font_path)) {
3418 fontname = NULL;
3419 }
3420 }
3421#endif /* VIRTUAL_DIR */
3422
3423 PHP_GD_CHECK_OPEN_BASEDIR(fontname, "Invalid font filename");
3424
3425 // libgd note: Those should return const char * ideally, but backward compatibility ..
3426 if (EXT) {
3427 error = gdImageStringFTEx(im, brect, col, fontname, ptsize, angle, x, y, str, &strex);
3428 } else {
3429 error = gdImageStringFT(im, brect, col, fontname, ptsize, angle, x, y, str);
3430 }
3431
3432 if (error) {
3435 }
3436
3438
3439 /* return array with the text's bounding box */
3440 for (i = 0; i < 8; i++) {
3442 }
3443}
3444/* }}} */
3445#endif /* HAVE_GD_FREETYPE */
3446
3447/* Section Filters */
3448#define PHP_GD_SINGLE_RES \
3449 zval *SIM; \
3450 gdImagePtr im_src; \
3451 if (zend_parse_parameters(1, "O", &SIM, gd_image_ce) == FAILURE) { \
3452 RETURN_THROWS(); \
3453 } \
3454 im_src = php_gd_libgdimageptr_from_zval_p(SIM);
3455
3456static void php_image_filter_negate(INTERNAL_FUNCTION_PARAMETERS)
3457{
3459
3460 if (gdImageNegate(im_src) == 1) {
3462 }
3463
3465}
3466
3467static void php_image_filter_grayscale(INTERNAL_FUNCTION_PARAMETERS)
3468{
3470
3471 if (gdImageGrayScale(im_src) == 1) {
3473 }
3474
3476}
3477
3478static void php_image_filter_brightness(INTERNAL_FUNCTION_PARAMETERS)
3479{
3480 zval *SIM;
3481 gdImagePtr im_src;
3482 zend_long brightness, tmp;
3483
3486 Z_PARAM_LONG(tmp)
3487 Z_PARAM_LONG(brightness)
3489
3491
3492 if (gdImageBrightness(im_src, (int)brightness) == 1) {
3494 }
3495
3497}
3498
3499static void php_image_filter_contrast(INTERNAL_FUNCTION_PARAMETERS)
3500{
3501 zval *SIM;
3502 gdImagePtr im_src;
3503 zend_long contrast, tmp;
3504
3507 Z_PARAM_LONG(tmp)
3508 Z_PARAM_LONG(contrast)
3510
3512
3513 if (gdImageContrast(im_src, (int)contrast) == 1) {
3515 }
3516
3518}
3519
3520static void php_image_filter_colorize(INTERNAL_FUNCTION_PARAMETERS)
3521{
3522 zval *SIM;
3523 gdImagePtr im_src;
3524 zend_long r,g,b,tmp;
3525 zend_long a = 0;
3526
3529 Z_PARAM_LONG(tmp)
3530 Z_PARAM_LONG(r)
3531 Z_PARAM_LONG(g)
3532 Z_PARAM_LONG(b)
3536
3538
3539 if (gdImageColor(im_src, (int) r, (int) g, (int) b, (int) a) == 1) {
3541 }
3542
3544}
3545
3546static void php_image_filter_edgedetect(INTERNAL_FUNCTION_PARAMETERS)
3547{
3549
3550 if (gdImageEdgeDetectQuick(im_src) == 1) {
3552 }
3553
3555}
3556
3557static void php_image_filter_emboss(INTERNAL_FUNCTION_PARAMETERS)
3558{
3560
3561 if (gdImageEmboss(im_src) == 1) {
3563 }
3564
3566}
3567
3568static void php_image_filter_gaussian_blur(INTERNAL_FUNCTION_PARAMETERS)
3569{
3571
3572 if (gdImageGaussianBlur(im_src) == 1) {
3574 }
3575
3577}
3578
3579static void php_image_filter_selective_blur(INTERNAL_FUNCTION_PARAMETERS)
3580{
3582
3583 if (gdImageSelectiveBlur(im_src) == 1) {
3585 }
3586
3588}
3589
3590static void php_image_filter_mean_removal(INTERNAL_FUNCTION_PARAMETERS)
3591{
3593
3594 if (gdImageMeanRemoval(im_src) == 1) {
3596 }
3597
3599}
3600
3601static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS)
3602{
3603 zval *SIM;
3604 zend_long tmp;
3605 gdImagePtr im_src;
3606 double weight;
3607
3610 Z_PARAM_LONG(tmp)
3611 Z_PARAM_DOUBLE(weight)
3613
3615
3616 if (gdImageSmooth(im_src, (float)weight)==1) {
3618 }
3619
3621}
3622
3623static void php_image_filter_pixelate(INTERNAL_FUNCTION_PARAMETERS)
3624{
3625 zval *IM;
3626 gdImagePtr im;
3627 zend_long tmp, blocksize;
3628 bool mode = false;
3629
3632 Z_PARAM_LONG(tmp)
3633 Z_PARAM_LONG(blocksize)
3637
3639
3640 if (gdImagePixelate(im, (int) blocksize, (const unsigned int) mode)) {
3642 }
3643
3645}
3646
3647static void php_image_filter_scatter(INTERNAL_FUNCTION_PARAMETERS)
3648{
3649 zval *IM;
3650 zval *hash_colors = NULL;
3651 gdImagePtr im;
3652 zend_long tmp;
3653 zend_long scatter_sub, scatter_plus;
3654
3657 Z_PARAM_LONG(tmp)
3658 Z_PARAM_LONG(scatter_sub)
3659 Z_PARAM_LONG(scatter_plus)
3661 Z_PARAM_ARRAY(hash_colors)
3663
3664 if (scatter_sub < 0 || ZEND_SIZE_T_INT_OVFL(scatter_sub)) {
3665 zend_argument_value_error(3, "must be between 0 and %d", INT_MAX);
3666 RETURN_THROWS();
3667 }
3668
3669 if (scatter_plus < 0 || ZEND_SIZE_T_INT_OVFL(scatter_plus)) {
3670 zend_argument_value_error(4, "must be between 0 and %d", INT_MAX);
3671 RETURN_THROWS();
3672 }
3673
3675
3676 if (hash_colors) {
3677 uint32_t i = 0;
3678 uint32_t num_colors = zend_hash_num_elements(Z_ARRVAL_P(hash_colors));
3679 zval *color;
3680 int *colors;
3681
3682 if (num_colors == 0) {
3683 RETURN_BOOL(gdImageScatter(im, (int)scatter_sub, (int)scatter_plus));
3684 }
3685
3686 colors = emalloc(num_colors * sizeof(int));
3687
3688 ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(hash_colors), color) {
3689 *(colors + i++) = (int) zval_get_long(color);
3691
3692 RETVAL_BOOL(gdImageScatterColor(im, (int)scatter_sub, (int)scatter_plus, colors, num_colors));
3693
3694 efree(colors);
3695 } else {
3696 RETURN_BOOL(gdImageScatter(im, (int) scatter_sub, (int) scatter_plus));
3697 }
3698}
3699
3700/* {{{ Applies Filter an image using a custom angle */
3702{
3703 zval *tmp;
3704
3705 typedef void (*image_filter)(INTERNAL_FUNCTION_PARAMETERS);
3706 zend_long filtertype;
3707 image_filter filters[] =
3708 {
3709 php_image_filter_negate ,
3710 php_image_filter_grayscale,
3711 php_image_filter_brightness,
3712 php_image_filter_contrast,
3713 php_image_filter_colorize,
3714 php_image_filter_edgedetect,
3715 php_image_filter_emboss,
3716 php_image_filter_gaussian_blur,
3717 php_image_filter_selective_blur,
3718 php_image_filter_mean_removal,
3719 php_image_filter_smooth,
3720 php_image_filter_pixelate,
3721 php_image_filter_scatter
3722 };
3723
3724 if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > IMAGE_FILTER_MAX_ARGS) {
3726 } else if (zend_parse_parameters(2, "Ol", &tmp, gd_image_ce, &filtertype) == FAILURE) {
3727 RETURN_THROWS();
3728 }
3729
3730 if (filtertype >= 0 && filtertype <= IMAGE_FILTER_MAX) {
3731 filters[filtertype](INTERNAL_FUNCTION_PARAM_PASSTHRU);
3732 }
3733}
3734/* }}} */
3735
3736/* {{{ Apply a 3x3 convolution matrix, using coefficient div and offset */
3738{
3739 zval *SIM, *hash_matrix;
3740 zval *var = NULL, *var2 = NULL;
3741 gdImagePtr im_src = NULL;
3742 double div, offset;
3743 int nelem, i, j, res;
3744 float matrix[3][3] = {{0,0,0}, {0,0,0}, {0,0,0}};
3745
3748 Z_PARAM_ARRAY(hash_matrix)
3749 Z_PARAM_DOUBLE(div)
3752
3754
3755 nelem = zend_hash_num_elements(Z_ARRVAL_P(hash_matrix));
3756 if (nelem != 3) {
3757 zend_argument_value_error(2, "must be a 3x3 array");
3758 RETURN_THROWS();
3759 }
3760
3761 for (i=0; i<3; i++) {
3762 if ((var = zend_hash_index_find_deref(Z_ARRVAL_P(hash_matrix), (i))) != NULL && Z_TYPE_P(var) == IS_ARRAY) {
3763 if (zend_hash_num_elements(Z_ARRVAL_P(var)) != 3 ) {
3764 zend_argument_value_error(2, "must be a 3x3 array, matrix[%d] only has %d elements", i, zend_hash_num_elements(Z_ARRVAL_P(var)));
3765 RETURN_THROWS();
3766 }
3767
3768 for (j=0; j<3; j++) {
3769 if ((var2 = zend_hash_index_find(Z_ARRVAL_P(var), j)) != NULL) {
3770 matrix[i][j] = (float) zval_get_double(var2);
3771 } else {
3772 zend_argument_value_error(2, "must be a 3x3 array, matrix[%d][%d] cannot be found (missing integer key)", i, j);
3773 RETURN_THROWS();
3774 }
3775 }
3776 }
3777 }
3778
3779 if (UNEXPECTED(!zend_finite(div))) {
3780 zend_argument_value_error(3, "must be finite");
3781 RETURN_THROWS();
3782 }
3783
3784 float div_float = (float) div;
3785 if (UNEXPECTED(div_float == 0.0f)) {
3786 zend_argument_value_error(3, "must not be 0");
3787 RETURN_THROWS();
3788 }
3789
3790 if (UNEXPECTED(!zend_finite(offset))) {
3791 zend_argument_value_error(4, "must be finite");
3792 RETURN_THROWS();
3793 }
3794
3795 res = gdImageConvolution(im_src, matrix, div_float, (float) offset);
3796
3797 if (res) {
3799 } else {
3801 }
3802}
3803/* }}} */
3804/* End section: Filters */
3805
3806/* {{{ Flip an image (in place) horizontally, vertically or both directions. */
3808{
3809 zval *IM;
3811 gdImagePtr im;
3812
3817
3819
3820 switch (mode) {
3823 break;
3824
3827 break;
3828
3829 case PHP_GD_FLIP_BOTH:
3830 gdImageFlipBoth(im);
3831 break;
3832
3833 default:
3834 zend_argument_value_error(2, "must be one of IMG_FLIP_VERTICAL, IMG_FLIP_HORIZONTAL, or IMG_FLIP_BOTH");
3835 RETURN_THROWS();
3836 }
3837
3839}
3840/* }}} */
3841
3842/* {{{ Should antialiased functions used or not*/
3844{
3845 zval *IM;
3846 bool alias;
3847 gdImagePtr im;
3848
3851 Z_PARAM_BOOL(alias)
3853
3855 if (im->trueColor) {
3856 im->AA = alias;
3857 }
3858
3860}
3861/* }}} */
3862
3863/* {{{ Crop an image using the given coordinates and size, x, y, width and height. */
3865{
3866 zval *IM;
3867 gdImagePtr im;
3868 gdImagePtr im_crop;
3869 gdRect rect;
3870 zval *z_rect;
3871 zval *tmp;
3872
3875 Z_PARAM_ARRAY(z_rect)
3877
3879
3880 if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "x", sizeof("x") -1)) != NULL) {
3881 rect.x = zval_get_long(tmp);
3882 } else {
3883 zend_argument_value_error(2, "must have an \"x\" key");
3884 RETURN_THROWS();
3885 }
3886
3887 if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "y", sizeof("y") - 1)) != NULL) {
3888 rect.y = zval_get_long(tmp);
3889 } else {
3890 zend_argument_value_error(2, "must have a \"y\" key");
3891 RETURN_THROWS();
3892 }
3893
3894 if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "width", sizeof("width") - 1)) != NULL) {
3895 rect.width = zval_get_long(tmp);
3896 } else {
3897 zend_argument_value_error(2, "must have a \"width\" key");
3898 RETURN_THROWS();
3899 }
3900
3901 if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "height", sizeof("height") - 1)) != NULL) {
3902 rect.height = zval_get_long(tmp);
3903 } else {
3904 zend_argument_value_error(2, "must have a \"height\" key");
3905 RETURN_THROWS();
3906 }
3907
3908 if ((rect.width > 0 && rect.x > INT_MAX - rect.width)) {
3909 zend_argument_value_error(2, "overflow with \"x\" and \"width\" keys");
3910 RETURN_THROWS();
3911 }
3912
3913 if ((rect.width < 0 && rect.x < INT_MIN - rect.width)) {
3914 zend_argument_value_error(2, "underflow with \"x\" and \"width\" keys");
3915 RETURN_THROWS();
3916 }
3917
3918 if ((rect.height > 0 && rect.y > INT_MAX - rect.height)) {
3919 zend_argument_value_error(2, "overflow with \"y\" and \"height\" keys");
3920 RETURN_THROWS();
3921 }
3922
3923 if ((rect.height < 0 && rect.y < INT_MIN - rect.height)) {
3924 zend_argument_value_error(2, "underflow with \"y\" and \"height\" keys");
3925 RETURN_THROWS();
3926 }
3927
3928 im_crop = gdImageCrop(im, &rect);
3929
3930 if (im_crop == NULL) {
3932 }
3933
3935}
3936/* }}} */
3937
3938/* {{{ Crop an image automatically using one of the available modes. */
3940{
3941 zval *IM;
3943 zend_long color = -1;
3944 double threshold = 0.5f;
3945 gdImagePtr im;
3946 gdImagePtr im_crop;
3947
3952 Z_PARAM_DOUBLE(threshold)
3955
3957
3958 switch (mode) {
3959 case GD_CROP_DEFAULT:
3961 case GD_CROP_BLACK:
3962 case GD_CROP_WHITE:
3963 case GD_CROP_SIDES:
3964 im_crop = gdImageCropAuto(im, mode);
3965 break;
3966
3967 case GD_CROP_THRESHOLD:
3968 if (color < 0 || (!gdImageTrueColor(im) && color >= gdImageColorsTotal(im))) {
3969 zend_argument_value_error(4, "must be greater than or equal to 0 when using the threshold mode");
3970 RETURN_THROWS();
3971 }
3972 im_crop = gdImageCropThreshold(im, color, (float) threshold);
3973 break;
3974
3975 default:
3976 zend_argument_value_error(2, "must be a valid mode");
3977 RETURN_THROWS();
3978 }
3979
3980 if (im_crop == NULL) {
3982 }
3983
3985}
3986/* }}} */
3987
3988/* {{{ Scale an image using the given new width and height. */
3990{
3991 zval *IM;
3992 gdImagePtr im;
3993 gdImagePtr im_scaled = NULL;
3994 int new_width, new_height;
3995 zend_long tmp_w, tmp_h=-1, tmp_m = GD_BILINEAR_FIXED;
3996 gdInterpolationMethod method, old_method;
3997
4000 Z_PARAM_LONG(tmp_w)
4002 Z_PARAM_LONG(tmp_h)
4003 Z_PARAM_LONG(tmp_m)
4005
4006 if (tmp_m < GD_DEFAULT || tmp_m >= GD_METHOD_COUNT) {
4007 zend_argument_value_error(4, "must be one of the GD_* constants");
4008 RETURN_THROWS();
4009 }
4010
4011 method = tmp_m;
4012
4014
4015 if (tmp_h < 0 && tmp_w < 0) {
4016 zend_value_error("Argument #2 ($width) and argument #3 ($height) cannot be both negative");
4017 RETURN_THROWS();
4018 }
4019
4020 if (tmp_h < 0 || tmp_w < 0) {
4021 /* preserve ratio */
4022 long src_x, src_y;
4023
4024 src_x = gdImageSX(im);
4025 src_y = gdImageSY(im);
4026
4027 if (src_x && tmp_h < 0) {
4028 tmp_h = tmp_w * src_y / src_x;
4029 }
4030 if (src_y && tmp_w < 0) {
4031 tmp_w = tmp_h * src_x / src_y;
4032 }
4033 }
4034
4035 if (tmp_w <= 0 || ZEND_SIZE_T_INT_OVFL(tmp_w)) {
4036 zend_argument_value_error(2, "must be between 1 and %d", INT_MAX);
4037 RETURN_THROWS();
4038 }
4039
4040 if (tmp_h <= 0 || ZEND_SIZE_T_INT_OVFL(tmp_h)) {
4041 zend_argument_value_error(3, "must be between 1 and %d", INT_MAX);
4042 RETURN_THROWS();
4043 }
4044
4045
4046 new_width = tmp_w;
4047 new_height = tmp_h;
4048
4049 /* gdImageGetInterpolationMethod() is only available as of GD 2.1.1 */
4050 old_method = im->interpolation_id;
4051 if (gdImageSetInterpolationMethod(im, method)) {
4052 im_scaled = gdImageScale(im, new_width, new_height);
4053 }
4054 gdImageSetInterpolationMethod(im, old_method);
4055
4056 if (im_scaled == NULL) {
4058 }
4059
4061}
4062/* }}} */
4063
4064/* {{{ Return an image containing the affine tramsformed src image, using an optional clipping area */
4066{
4067 zval *IM;
4068 gdImagePtr src;
4069 gdImagePtr dst;
4070 gdRect rect;
4071 gdRectPtr pRect = NULL;
4072 zval *z_rect = NULL;
4073 zval *z_affine;
4074 zval *tmp;
4075 double affine[6];
4076 int i, nelems;
4077 zval *zval_affine_elem = NULL;
4078
4081 Z_PARAM_ARRAY(z_affine)
4083 Z_PARAM_ARRAY_OR_NULL(z_rect)
4085
4086
4088
4089 if ((nelems = zend_hash_num_elements(Z_ARRVAL_P(z_affine))) != 6) {
4090 zend_argument_value_error(2, "must have 6 elements");
4091 RETURN_THROWS();
4092 }
4093
4094 for (i = 0; i < nelems; i++) {
4095 if ((zval_affine_elem = zend_hash_index_find_deref(Z_ARRVAL_P(z_affine), i)) != NULL) {
4096 switch (Z_TYPE_P(zval_affine_elem)) {
4097 case IS_LONG:
4098 affine[i] = Z_LVAL_P(zval_affine_elem);
4099 if (affine[i] < INT_MIN || affine[i] > INT_MAX) {
4100 zend_argument_value_error(2, "element %i must be between %d and %d", i, INT_MIN, INT_MAX);
4101 RETURN_THROWS();
4102 }
4103 break;
4104 case IS_DOUBLE:
4105 affine[i] = Z_DVAL_P(zval_affine_elem);
4106 if (affine[i] < INT_MIN || affine[i] > INT_MAX) {
4107 zend_argument_value_error(2, "element %i must be between %d and %d", i, INT_MIN, INT_MAX);
4108 RETURN_THROWS();
4109 }
4110 break;
4111 case IS_STRING:
4112 affine[i] = zval_get_double(zval_affine_elem);
4113 if (affine[i] < INT_MIN || affine[i] > INT_MAX) {
4114 zend_argument_value_error(2, "element %i must be between %d and %d", i, INT_MIN, INT_MAX);
4115 RETURN_THROWS();
4116 }
4117 break;
4118 default:
4119 zend_argument_type_error(3, "contains invalid type for element %i", i);
4120 RETURN_THROWS();
4121 }
4122 }
4123 }
4124
4125 if (z_rect != NULL) {
4126 if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "x", sizeof("x") - 1)) != NULL) {
4127 rect.x = zval_get_long(tmp);
4128 } else {
4129 zend_argument_value_error(3, "must have an \"x\" key");
4130 RETURN_THROWS();
4131 }
4132
4133 if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "y", sizeof("y") - 1)) != NULL) {
4134 rect.y = zval_get_long(tmp);
4135 } else {
4136 zend_argument_value_error(3, "must have a \"y\" key");
4137 RETURN_THROWS();
4138 }
4139
4140 if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "width", sizeof("width") - 1)) != NULL) {
4141 rect.width = zval_get_long(tmp);
4142 } else {
4143 zend_argument_value_error(3, "must have a \"width\" key");
4144 RETURN_THROWS();
4145 }
4146
4147 if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "height", sizeof("height") - 1)) != NULL) {
4148 rect.height = zval_get_long(tmp);
4149 } else {
4150 zend_argument_value_error(3, "must have a \"height\" key");
4151 RETURN_THROWS();
4152 }
4153 pRect = &rect;
4154 }
4155
4156 if (gdTransformAffineGetImage(&dst, src, pRect, affine) != GD_TRUE) {
4158 }
4159
4160 if (dst == NULL) {
4162 }
4163
4165}
4166/* }}} */
4167
4168/* {{{ Return an image containing the affine tramsformed src image, using an optional clipping area */
4170{
4171 double affine[6];
4173 zval *options = NULL;
4174 zval *tmp;
4175 int res = GD_FALSE, i;
4176
4181
4182 switch((gdAffineStandardMatrix)type) {
4184 case GD_AFFINE_SCALE: {
4185 double x, y;
4186 if (Z_TYPE_P(options) != IS_ARRAY) {
4187 zend_argument_type_error(1, "must be of type array when using translate or scale");
4188 RETURN_THROWS();
4189 }
4190
4191 if ((tmp = zend_hash_str_find(Z_ARRVAL_P(options), "x", sizeof("x") - 1)) != NULL) {
4192 x = zval_get_double(tmp);
4193 } else {
4194 zend_argument_value_error(2, "must have an \"x\" key");
4195 RETURN_THROWS();
4196 }
4197
4198 if ((tmp = zend_hash_str_find(Z_ARRVAL_P(options), "y", sizeof("y") - 1)) != NULL) {
4199 y = zval_get_double(tmp);
4200 } else {
4201 zend_argument_value_error(2, "must have a \"y\" key");
4202 RETURN_THROWS();
4203 }
4204
4205 if (type == GD_AFFINE_TRANSLATE) {
4206 res = gdAffineTranslate(affine, x, y);
4207 } else {
4208 res = gdAffineScale(affine, x, y);
4209 }
4210 break;
4211 }
4212
4213 case GD_AFFINE_ROTATE:
4216 double angle;
4217
4218 angle = zval_get_double(options);
4219
4221 res = gdAffineShearHorizontal(affine, angle);
4222 } else if (type == GD_AFFINE_SHEAR_VERTICAL) {
4223 res = gdAffineShearVertical(affine, angle);
4224 } else {
4225 res = gdAffineRotate(affine, angle);
4226 }
4227 break;
4228 }
4229
4230 default:
4231 zend_argument_value_error(1, "must be a valid element type");
4232 RETURN_THROWS();
4233 }
4234
4235 if (res == GD_FALSE) {
4237 } else {
4239 for (i = 0; i < 6; i++) {
4240 add_index_double(return_value, i, affine[i]);
4241 }
4242 }
4243} /* }}} */
4244
4245/* {{{ Concat two matrices (as in doing many ops in one go) */
4247{
4248 double m1[6];
4249 double m2[6];
4250 double mr[6];
4251
4252 zval *tmp;
4253 zval *z_m1;
4254 zval *z_m2;
4255 int i;
4256
4258 Z_PARAM_ARRAY(z_m1)
4259 Z_PARAM_ARRAY(z_m2)
4261
4262 if (zend_hash_num_elements(Z_ARRVAL_P(z_m1)) != 6) {
4263 zend_argument_value_error(1, "must have 6 elements");
4264 RETURN_THROWS();
4265 }
4266
4267 if (zend_hash_num_elements(Z_ARRVAL_P(z_m2)) != 6) {
4268 zend_argument_value_error(1, "must have 6 elements");
4269 RETURN_THROWS();
4270 }
4271
4272 for (i = 0; i < 6; i++) {
4273 if ((tmp = zend_hash_index_find_deref(Z_ARRVAL_P(z_m1), i)) != NULL) {
4274 switch (Z_TYPE_P(tmp)) {
4275 case IS_LONG:
4276 m1[i] = Z_LVAL_P(tmp);
4277 break;
4278 case IS_DOUBLE:
4279 m1[i] = Z_DVAL_P(tmp);
4280 break;
4281 case IS_STRING:
4282 m1[i] = zval_get_double(tmp);
4283 break;
4284 default:
4285 zend_argument_type_error(1, "contains invalid type for element %i", i);
4286 RETURN_THROWS();
4287 }
4288 }
4289
4290 if ((tmp = zend_hash_index_find_deref(Z_ARRVAL_P(z_m2), i)) != NULL) {
4291 switch (Z_TYPE_P(tmp)) {
4292 case IS_LONG:
4293 m2[i] = Z_LVAL_P(tmp);
4294 break;
4295 case IS_DOUBLE:
4296 m2[i] = Z_DVAL_P(tmp);
4297 break;
4298 case IS_STRING:
4299 m2[i] = zval_get_double(tmp);
4300 break;
4301 default:
4302 zend_argument_type_error(2, "contains invalid type for element %i", i);
4303 RETURN_THROWS();
4304 }
4305 }
4306 }
4307
4308 if (gdAffineConcat (mr, m1, m2) != GD_TRUE) {
4310 }
4311
4313 for (i = 0; i < 6; i++) {
4314 add_index_double(return_value, i, mr[i]);
4315 }
4316} /* }}} */
4317
4318/* {{{ Get the default interpolation method. */
4320{
4321 zval *IM;
4322 gdImagePtr im;
4323
4327
4329
4330#ifdef HAVE_GD_GET_INTERPOLATION
4332#else
4334#endif
4335}
4336/* }}} */
4337
4338/* {{{ Set the default interpolation method, passing -1 or 0 sets it to the libgd default (bilinear). */
4340{
4341 zval *IM;
4342 gdImagePtr im;
4344
4348 Z_PARAM_LONG(method)
4350
4352
4353 if (method == -1) {
4354 method = GD_BILINEAR_FIXED;
4355 }
4357}
4358/* }}} */
4359
4360/* {{{ Get or set the resolution of the image in DPI. */
4362{
4363 zval *IM;
4364 gdImagePtr im;
4365 zend_long res_x, res_y;
4366 bool res_x_is_null = true, res_y_is_null = true;
4367
4371 Z_PARAM_LONG_OR_NULL(res_x, res_x_is_null)
4372 Z_PARAM_LONG_OR_NULL(res_y, res_y_is_null)
4374
4376
4377 if (!res_x_is_null && !res_y_is_null) {
4378 if (res_x < 0 || ZEND_SIZE_T_UINT_OVFL(res_x)) {
4379 zend_argument_value_error(2, "must be between 0 and %u", UINT_MAX);
4380 RETURN_THROWS();
4381 }
4382 if (res_y < 0 || ZEND_SIZE_T_UINT_OVFL(res_y)) {
4383 zend_argument_value_error(3, "must be between 0 and %u", UINT_MAX);
4384 RETURN_THROWS();
4385 }
4386 gdImageSetResolution(im, res_x, res_y);
4388 } else if (!res_x_is_null && res_y_is_null) {
4389 if (res_x < 0 || ZEND_SIZE_T_UINT_OVFL(res_x)) {
4390 zend_argument_value_error(2, "must be between 0 and %u", UINT_MAX);
4391 RETURN_THROWS();
4392 }
4393 gdImageSetResolution(im, res_x, res_x);
4395 } else if (res_x_is_null && !res_y_is_null) {
4396 if (res_y < 0 || ZEND_SIZE_T_UINT_OVFL(res_y)) {
4397 zend_argument_value_error(3, "must be between 0 and %u", UINT_MAX);
4398 RETURN_THROWS();
4399 }
4400 gdImageSetResolution(im, res_y, res_y);
4402 }
4403
4407}
4408/* }}} */
4409
4410
4411/*********************************************************
4412 *
4413 * Stream Handling
4414 * Formerly contained within ext/gd/gd_ctx.c and included
4415 * at the the top of this file
4416 *
4417 ********************************************************/
4418
4419#define CTX_PUTC(c,ctx) ctx->putC(ctx, c)
4420
4421static void _php_image_output_putc(struct gdIOCtx *ctx, int c) /* {{{ */
4422{
4423 /* without the following downcast, the write will fail
4424 * (i.e., will write a zero byte) for all
4425 * big endian architectures:
4426 */
4427 unsigned char ch = (unsigned char) c;
4428 php_write(&ch, 1);
4429} /* }}} */
4430
4431static int _php_image_output_putbuf(struct gdIOCtx *ctx, const void* buf, int l) /* {{{ */
4432{
4433 return php_write((void *)buf, l);
4434} /* }}} */
4435
4436static void _php_image_output_ctxfree(struct gdIOCtx *ctx) /* {{{ */
4437{
4438 efree(ctx);
4439} /* }}} */
4440
4441static void _php_image_stream_putc(struct gdIOCtx *ctx, int c) /* {{{ */ {
4442 char ch = (char) c;
4443 php_stream * stream = (php_stream *)ctx->data;
4444 php_stream_write(stream, &ch, 1);
4445} /* }}} */
4446
4447static int _php_image_stream_putbuf(struct gdIOCtx *ctx, const void* buf, int l) /* {{{ */
4448{
4449 php_stream * stream = (php_stream *)ctx->data;
4450 return php_stream_write(stream, (void *)buf, l);
4451} /* }}} */
4452
4453static void _php_image_stream_ctxfree(struct gdIOCtx *ctx) /* {{{ */
4454{
4455 if(ctx->data) {
4456 ctx->data = NULL;
4457 }
4458 efree(ctx);
4459} /* }}} */
4460
4461static void _php_image_stream_ctxfreeandclose(struct gdIOCtx *ctx) /* {{{ */
4462{
4463 if(ctx->data) {
4465 ctx->data = NULL;
4466 }
4467 efree(ctx);
4468} /* }}} */
4469
4470static gdIOCtx *create_stream_context(php_stream *stream, int close_stream) {
4471 gdIOCtx *ctx = ecalloc(1, sizeof(gdIOCtx));
4472
4473 ctx->putC = _php_image_stream_putc;
4474 ctx->putBuf = _php_image_stream_putbuf;
4475 if (close_stream) {
4476 ctx->gd_free = _php_image_stream_ctxfreeandclose;
4477 } else {
4478 ctx->gd_free = _php_image_stream_ctxfree;
4479 }
4480 ctx->data = (void *)stream;
4481
4482 return ctx;
4483}
4484
4485static gdIOCtx *create_output_context(zval *to_zval, uint32_t arg_num) {
4486 gdIOCtx *ctx;
4487
4488 if (to_zval != NULL) {
4489 php_stream *stream;
4490 int close_stream = 1;
4491
4492 ZEND_ASSERT(arg_num > 0);
4493
4494 if (Z_TYPE_P(to_zval) == IS_RESOURCE) {
4495 php_stream_from_zval_no_verify(stream, to_zval);
4496 if (stream == NULL) {
4497 return NULL;
4498 }
4499 close_stream = 0;
4500 } else if (Z_TYPE_P(to_zval) == IS_STRING) {
4501 if (CHECK_ZVAL_NULL_PATH(to_zval)) {
4502 zend_argument_type_error(arg_num, "must not contain null bytes");
4503 return NULL;
4504 }
4505
4507 if (stream == NULL) {
4508 return NULL;
4509 }
4510 } else {
4511 zend_argument_type_error(arg_num, "must be a file name or a stream resource, %s given", zend_zval_value_name(to_zval));
4512 return NULL;
4513 }
4514
4515 ctx = create_stream_context(stream, close_stream);
4516 } else {
4517 ctx = ecalloc(1, sizeof(gdIOCtx));
4518
4519 ctx->putC = _php_image_output_putc;
4520 ctx->putBuf = _php_image_output_putbuf;
4521 ctx->gd_free = _php_image_output_ctxfree;
4522 }
4523
4524 return ctx;
4525}
4526
4527/* }}} */
matrix($n)
Definition bench.php:292
file(string $filename, int $flags=0, $context=null)
fseek($stream, int $offset, int $whence=SEEK_SET)
fclose($stream)
fread($stream, int $length)
fflush($stream)
pow(mixed $num, mixed $exponent)
error($message)
Definition ext_skel.php:22
zend_ffi_type * type
Definition ffi.c:3812
zend_long ch
Definition ffi.c:4580
zend_long n
Definition ffi.c:4979
zend_string * res
Definition ffi.c:4692
memcpy(ptr1, ptr2, size)
zval * arg
Definition ffi.c:3975
memset(ptr, 0, type->size)
zval * val
Definition ffi.c:4262
zend_ffi_ctype_name_buf buf
Definition ffi.c:4685
const SEEK_END
Definition file.stub.php:21
#define X
Definition encoding.c:238
zend_long offset
char * mode
#define CHECK_RGBA_RANGE(component, name, argument_number)
Definition gd.c:945
#define TTFTEXT_BBOX
Definition gd.c:3340
#define PHP_GD_SINGLE_RES
Definition gd.c:3448
void php_gd_assign_libgdimageptr_as_extgdimage(zval *val, gdImagePtr image)
Definition gd.c:195
struct _php_gd_font_object php_gd_font_object
zend_module_entry gd_module_entry
Definition gd.c:287
struct _gd_ext_image_object php_gd_image_object
zend_class_entry * gd_image_ce
Definition gd.c:134
void php_gd_error_method(int type, const char *format, va_list args)
Definition gd.c:311
zend_object * php_gd_image_object_create(zend_class_entry *class_type)
Definition gd.c:168
#define FLIPWORD(a)
Definition gd.c:525
#define PHP_GD_FLIP_HORIZONTAL
Definition gd.c:92
#define PHP_GD_FLIP_VERTICAL
Definition gd.c:93
#define PHP_GD_FLIP_BOTH
Definition gd.c:94
#define PHP_GD_VERSION_STRING
Definition gd.c:374
int overflow2(int a, int b)
Definition gd_compat.c:10
#define M_PI
Definition gd.c:88
#define TTFTEXT_DRAW
Definition gd.c:3339
PHP_GD_API gdImagePtr php_gd_libgdimageptr_from_zval_p(zval *zp)
Definition gd.c:162
#define gdImageBlue(im, c)
Definition gd.h:775
char * gdImageStringFTEx(gdImage *im, int *brect, int fg, char *fontlist, double ptsize, double angle, int x, int y, char *string, gdFTStringExtraPtr strex)
Definition gdft.c:48
#define gdTrueColorGetBlue(c)
Definition gd.h:88
int gdImageScatterColor(gdImagePtr im, int sub, int plus, int colors[], unsigned int num_colors)
Definition gd_filter.c:40
void gdImageJpegCtx(gdImagePtr im, gdIOCtx *out, int quality)
#define gdImageResolutionX(im)
Definition gd.h:789
void gdFontCacheMutexShutdown(void)
gdImagePtr gdImageCreateFromGifCtx(gdIOCtxPtr in)
Definition gd_gif_in.c:128
int gdTransformAffineGetImage(gdImagePtr *dst, const gdImagePtr src, gdRectPtr src_area, const double affine[6])
int gdImageSetInterpolationMethod(gdImagePtr im, gdInterpolationMethod id)
int gdAffineShearVertical(double dst[6], const double angle)
Definition gd_matrix.c:244
int gdImageEdgeDetectQuick(gdImagePtr src)
Definition gd_filter.c:516
gdImagePtr gdImageCreateFromBmpCtx(gdIOCtxPtr infile)
Definition gd_bmp.c:436
gdImagePtr gdImageCreateFromPngCtx(gdIOCtxPtr in)
struct gdRect * gdRectPtr
gdImagePtr gdImageCreateFromGd2Ctx(gdIOCtxPtr in)
Definition gd_gd2.c:267
#define GD_FALSE
Definition gd.h:96
#define gdTrueColorGetGreen(c)
Definition gd.h:87
#define gdImageTrueColor(im)
Definition gd.h:766
gdImagePtr gdImageCreateFromGif(FILE *fd)
Definition gd_gif_in.c:115
int gdImageNegate(gdImagePtr src)
Definition gd_filter.c:114
#define gdImageTrueColorPixel(im, x, y)
Definition gd.h:788
int gdImageTrueColorToPalette(gdImagePtr im, int ditherFlag, int colorsWanted)
Definition gd_topal.c:1440
gdImagePtr gdImageCreateFromXbm(FILE *fd)
Definition gd_xbm.c:32
#define GD_TRUE
Definition gd.h:95
gdImagePtr gdImageCreateFromTgaCtx(gdIOCtx *ctx)
Definition gd_tga.c:62
gdImagePtr gdImageScale(const gdImagePtr src, const unsigned int new_width, const unsigned int new_height)
gdImagePtr gdImageCreateFromWebp(FILE *fd)
@ GD_CROP_TRANSPARENT
Definition gd.h:871
@ GD_CROP_THRESHOLD
Definition gd.h:875
@ GD_CROP_WHITE
Definition gd.h:873
@ GD_CROP_BLACK
Definition gd.h:872
@ GD_CROP_SIDES
Definition gd.h:874
@ GD_CROP_DEFAULT
Definition gd.h:870
#define gdTrueColorGetAlpha(c)
Definition gd.h:85
#define gdAntiAliased
Definition gd.h:335
void gdFontCacheMutexSetup(void)
#define gdImageGetTransparent(im)
Definition gd.h:779
gdImagePtr gdImageCreateFromGd2Part(FILE *in, int srcx, int srcy, int w, int h)
Definition gd_gd2.c:422
gdImagePtr gdImageCreateFromAvifCtx(gdIOCtx *infile)
int gdImageGaussianBlur(gdImagePtr im)
Definition gd_filter.c:525
int gdAffineConcat(double dst[6], const double m1[6], const double m2[6])
Definition gd_matrix.c:121
gdImagePtr gdImageCreateFromWBMPCtx(gdIOCtx *infile)
Definition gd_wbmp.c:141
int gdAffineRotate(double dst[6], const double angle)
Definition gd_matrix.c:197
void gdImageAvifCtx(gdImagePtr im, gdIOCtx *outfile, int quality, int speed)
void gdFontCacheShutdown(void)
gdInterpolationMethod gdImageGetInterpolationMethod(gdImagePtr im)
gdFont * gdFontPtr
Definition gd.h:288
gdImagePtr gdImageCreateFromJpegCtx(gdIOCtx *infile)
gdImagePtr gdImageCreateFromTga(FILE *fp)
Definition gd_tga.c:30
#define gdImageSY(im)
Definition gd.h:769
const char * gdJpegGetVersionString(void)
gdImagePtr gdImageCreateFromJpeg(FILE *infile)
int gdImageEmboss(gdImagePtr im)
Definition gd_filter.c:534
void gdImageFlipVertical(gdImagePtr im)
Definition gd_transform.c:3
gdImagePtr gdImageRotateInterpolated(const gdImagePtr src, const float angle, int bgcolor)
int gdImageConvolution(gdImagePtr src, float ft[3][3], float filter_div, float offset)
Definition gd_filter.c:335
#define gdTrueColorGetRed(c)
Definition gd.h:86
gdImagePtr gdImageCreateFromXpm(char *filename)
int gdAffineTranslate(double dst[6], const double offset_x, const double offset_y)
Definition gd_matrix.c:267
char * gdImageStringFT(gdImage *im, int *brect, int fg, char *fontlist, double ptsize, double angle, int x, int y, char *string)
Definition gdft.c:56
void gdImageGd(gdImagePtr im, FILE *out)
Definition gd_gd.c:265
gdImagePtr gdImageCropAuto(gdImagePtr im, const unsigned int mode)
Definition gd_crop.c:79
int gdAffineShearHorizontal(double dst[6], const double angle)
Definition gd_matrix.c:222
#define gdImageSX(im)
Definition gd.h:768
gdImagePtr gdImageCrop(gdImagePtr src, const gdRectPtr crop)
Definition gd_crop.c:44
void gdImagePngCtxEx(gdImagePtr im, gdIOCtx *out, int level, int basefilter)
gdImagePtr gdImageCreateFromGd2PartCtx(gdIOCtxPtr in, int srcx, int srcy, int w, int h)
void gdImageWBMPCtx(gdImagePtr image, int fg, gdIOCtx *out)
Definition gd_wbmp.c:96
#define gdImageColorsTotal(im)
Definition gd.h:770
gdImagePtr gdImageCreateFromAvif(FILE *infile)
int gdImagePixelate(gdImagePtr im, int block_size, const unsigned int mode)
Definition gd_pixelate.c:3
int gdImageColor(gdImagePtr src, const int red, const int green, const int blue, const int alpha)
Definition gd_filter.c:292
void gdImageFlipBoth(gdImagePtr im)
gdAffineStandardMatrix
Definition gd.h:898
@ GD_AFFINE_SCALE
Definition gd.h:900
@ GD_AFFINE_SHEAR_HORIZONTAL
Definition gd.h:902
@ GD_AFFINE_SHEAR_VERTICAL
Definition gd.h:903
@ GD_AFFINE_TRANSLATE
Definition gd.h:899
@ GD_AFFINE_ROTATE
Definition gd.h:901
gdImagePtr gdImageCreateFromBmp(FILE *inFile)
Definition gd_bmp.c:410
gdInterpolationMethod
Definition gd.h:139
@ GD_BILINEAR_FIXED
Definition gd.h:143
@ GD_METHOD_COUNT
Definition gd.h:162
gdImagePtr gdImageCreateFromWBMP(FILE *inFile)
Definition gd_wbmp.c:183
int gdImageColorMatch(gdImagePtr im1, gdImagePtr im2)
#define gdTrueColorAlpha(r, g, b, a)
Definition gd.h:545
void gdImageGifCtx(gdImagePtr im, gdIOCtx *out)
int gdImageMeanRemoval(gdImagePtr im)
Definition gd_filter.c:548
gdImagePtr gdImageCreateFromJpegEx(FILE *infile, int ignore_warning)
gdImagePtr gdImageCropThreshold(gdImagePtr im, const unsigned int color, const float threshold)
Definition gd_crop.c:181
#define gdImageGreen(im, c)
Definition gd.h:773
void gdImageWebpCtx(gdImagePtr im, gdIOCtx *outfile, int quality)
void gdImageFlipHorizontal(gdImagePtr im)
#define gdImageResolutionY(im)
Definition gd.h:790
struct gdPoint * gdPointPtr
gdImagePtr gdImageCreateFromGdCtx(gdIOCtxPtr in)
Definition gd_gd.c:165
int gdImageContrast(gdImagePtr src, double contrast)
Definition gd_filter.c:232
const char * gdPngGetVersionString(void)
#define gdTrueColor(r, g, b)
Definition gd.h:537
int gdImageBrightness(gdImagePtr src, int brightness)
Definition gd_filter.c:187
int gdImageSmooth(gdImagePtr im, float weight)
Definition gd_filter.c:557
int gdAffineScale(double dst[6], const double scale_x, const double scale_y)
Definition gd_matrix.c:172
gdIOCtx * gdNewDynamicCtxEx(int size, void *data, int freeFlag)
Definition gd_io_dp.c:70
int gdImageGrayScale(gdImagePtr src)
Definition gd_filter.c:147
gdImagePtr gdImageCreateFromGd(FILE *in)
Definition gd_gd.c:142
void gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression)
Definition gd_bmp.c:91
void gdImageGd2(gdImagePtr im, FILE *out, int cs, int fmt)
Definition gd_gd2.c:832
#define gdImageGetInterlaced(im)
Definition gd.h:780
gdImagePtr gdImageCreateFromGd2(FILE *in)
Definition gd_gd2.c:245
#define gdImageAlpha(im, c)
Definition gd.h:777
#define gdImageBoundsSafe(im, x, y)
Definition gd.h:948
gdImagePtr gdImageCreateFromWebpCtx(gdIOCtxPtr in)
gdImagePtr gdImageCreateFromPng(FILE *fd)
int gdImageSelectiveBlur(gdImagePtr src)
Definition gd_filter.c:397
#define gdFTEX_LINESPACE
Definition gd.h:485
int gdImageScatter(gdImagePtr im, int sub, int plus)
Definition gd_filter.c:29
#define gdImageRed(im, c)
Definition gd.h:771
void gdImageXbmCtx(gdImagePtr image, char *file_name, int fg, gdIOCtx *out)
Definition gd_xbm.c:177
gdImage * gdImagePtr
Definition gd.h:248
imagecharup(GdImage $image, GdFont|int $font, int $x, int $y, string $char, int $color)
Definition gd.stub.php:702
imagebmp(GdImage $image, $file=null, bool $compressed=true)
Definition gd.stub.php:635
imagecreatefromgif(string $filename)
Definition gd.stub.php:555
imagesx(GdImage $image)
Definition gd.stub.php:716
imagefilledpolygon(GdImage $image, array $points, int $num_points_or_color, ?int $color=null)
Definition gd.stub.php:694
imagecreatefromgd2(string $filename)
Definition gd.stub.php:587
imagecreatetruecolor(int $width, int $height)
Definition gd.stub.php:491
imagepalettecopy(GdImage $dst, GdImage $src)
Definition gd.stub.php:642
imagefilledrectangle(GdImage $image, int $x1, int $y1, int $x2, int $y2, int $color)
Definition gd.stub.php:674
imageaffinematrixconcat(array $matrix1, array $matrix2)
Definition gd.stub.php:786
imagetruecolortopalette(GdImage $image, bool $dither, int $num_colors)
Definition gd.stub.php:495
imageflip(GdImage $image, int $mode)
Definition gd.stub.php:759
imagefontwidth(GdFont|int $font)
Definition gd.stub.php:696
imagecreatefromwbmp(string $filename)
Definition gd.stub.php:581
imagecreate(int $width, int $height)
Definition gd.stub.php:541
imagerotate(GdImage $image, float $angle, int $background_color)
Definition gd.stub.php:534
imagecolorset(GdImage $image, int $color, int $red, int $green, int $blue, int $alpha=0)
Definition gd.stub.php:656
imagefontheight(GdFont|int $font)
Definition gd.stub.php:698
imagegrabscreen()
Definition gd.stub.php:529
imageopenpolygon(GdImage $image, array $points, int $num_points_or_color, ?int $color=null)
Definition gd.stub.php:692
imageantialias(GdImage $image, bool $enable)
Definition gd.stub.php:761
imagecopy(GdImage $dst_image, GdImage $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $src_width, int $src_height)
Definition gd.stub.php:708
imagejpeg(GdImage $image, $file=null, int $quality=-1)
Definition gd.stub.php:623
imagesetstyle(GdImage $image, array $style)
Definition gd.stub.php:488
imagecreatefromgd(string $filename)
Definition gd.stub.php:584
imagecopyresized(GdImage $dst_image, GdImage $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $dst_width, int $dst_height, int $src_width, int $src_height)
Definition gd.stub.php:714
imagecolortransparent(GdImage $image, ?int $color=null)
Definition gd.stub.php:686
imagecropauto(GdImage $image, int $mode=IMG_CROP_DEFAULT, float $threshold=0.5, int $color=-1)
Definition gd.stub.php:767
imagepng(GdImage $image, $file=null, int $quality=-1, int $filters=-1)
Definition gd.stub.php:613
imagecolorstotal(GdImage $image)
Definition gd.stub.php:684
imagearc(GdImage $image, int $center_x, int $center_y, int $width, int $height, int $start_angle, int $end_angle, int $color)
Definition gd.stub.php:676
imagedashedline(GdImage $image, int $x1, int $y1, int $x2, int $y2, int $color)
Definition gd.stub.php:670
imagecreatefromgd2part(string $filename, int $x, int $y, int $width, int $height)
Definition gd.stub.php:590
imagecopyresampled(GdImage $dst_image, GdImage $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $dst_width, int $dst_height, int $src_width, int $src_height)
Definition gd.stub.php:521
imageaffine(GdImage $image, array $affine, ?array $clip=null)
Definition gd.stub.php:773
imagecolorresolve(GdImage $image, int $red, int $green, int $blue)
Definition gd.stub.php:652
imagelayereffect(GdImage $image, int $effect)
Definition gd.stub.php:511
gd_info()
Definition gd.stub.php:484
imagecolormatch(GdImage $image1, GdImage $image2)
Definition gd.stub.php:499
imagestringup(GdImage $image, GdFont|int $font, int $x, int $y, string $string, int $color)
Definition gd.stub.php:706
imagecolorclosesthwb(GdImage $image, int $red, int $green, int $blue)
Definition gd.stub.php:648
imagefttext(GdImage $image, float $size, float $angle, int $x, int $y, int $color, string $font_filename, string $text, array $options=[])
Definition gd.stub.php:739
imagexbm(GdImage $image, ?string $filename, ?int $foreground_color=null)
Definition gd.stub.php:601
imagesetinterpolation(GdImage $image, int $method=IMG_BILINEAR_FIXED)
Definition gd.stub.php:790
imagecreatefromavif(string $filename)
Definition gd.stub.php:551
imagesetclip(GdImage $image, int $x1, int $y1, int $x2, int $y2)
Definition gd.stub.php:720
imagegif(GdImage $image, $file=null)
Definition gd.stub.php:609
imageloadfont(string $filename)
Definition gd.stub.php:486
imagescale(GdImage $image, int $width, int $height=-1, int $mode=IMG_BILINEAR_FIXED)
Definition gd.stub.php:770
imageellipse(GdImage $image, int $center_x, int $center_y, int $width, int $height, int $color)
Definition gd.stub.php:678
imagecolorexact(GdImage $image, int $red, int $green, int $blue)
Definition gd.stub.php:654
imagecolorsforindex(GdImage $image, int $color)
Definition gd.stub.php:662
imagedestroy(GdImage $image)
Definition gd.stub.php:638
imageavif(GdImage $image, $file=null, int $quality=-1, int $speed=-1)
Definition gd.stub.php:605
imageftbbox(float $size, float $angle, string $font_filename, string $string, array $options=[])
Definition gd.stub.php:733
imagecreatefrompng(string $filename)
Definition gd.stub.php:564
imageinterlace(GdImage $image, ?bool $enable=null)
Definition gd.stub.php:688
imagecreatefromwebp(string $filename)
Definition gd.stub.php:569
imagerectangle(GdImage $image, int $x1, int $y1, int $x2, int $y2, int $color)
Definition gd.stub.php:672
imagecolorallocatealpha(GdImage $image, int $red, int $green, int $blue, int $alpha)
Definition gd.stub.php:513
imagepolygon(GdImage $image, array $points, int $num_points_or_color, ?int $color=null)
Definition gd.stub.php:690
imagecopymerge(GdImage $dst_image, GdImage $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $src_width, int $src_height, int $pct)
Definition gd.stub.php:710
imagecolorallocate(GdImage $image, int $red, int $green, int $blue)
Definition gd.stub.php:640
imagesetpixel(GdImage $image, int $x, int $y, int $color)
Definition gd.stub.php:666
imagecreatefromxbm(string $filename)
Definition gd.stub.php:573
imagealphablending(GdImage $image, bool $enable)
Definition gd.stub.php:507
imagesy(GdImage $image)
Definition gd.stub.php:718
imagefilter(GdImage $image, int $filter,... $args)
Definition gd.stub.php:755
imagecolordeallocate(GdImage $image, int $color)
Definition gd.stub.php:650
imagewbmp(GdImage $image, $file=null, ?int $foreground_color=null)
Definition gd.stub.php:627
imagesetthickness(GdImage $image, int $thickness)
Definition gd.stub.php:501
imagesettile(GdImage $image, GdImage $tile)
Definition gd.stub.php:536
imagecreatefromjpeg(string $filename)
Definition gd.stub.php:559
imagefill(GdImage $image, int $x, int $y, int $color)
Definition gd.stub.php:682
imagetypes()
Definition gd.stub.php:544
imagecreatefromstring(string $data)
Definition gd.stub.php:547
imagegrabwindow(int $handle, bool $client_area=false)
Definition gd.stub.php:526
imagegd2(GdImage $image, ?string $file=null, int $chunk_size=128, int $mode=IMG_GD2_RAW)
Definition gd.stub.php:631
imagechar(GdImage $image, GdFont|int $font, int $x, int $y, string $char, int $color)
Definition gd.stub.php:700
imagecreatefromtga(string $filename)
Definition gd.stub.php:598
imagecolorexactalpha(GdImage $image, int $red, int $green, int $blue, int $alpha)
Definition gd.stub.php:519
imagegd(GdImage $image, ?string $file=null)
Definition gd.stub.php:629
imagecolorat(GdImage $image, int $x, int $y)
Definition gd.stub.php:644
imageresolution(GdImage $image, ?int $resolution_x=null, ?int $resolution_y=null)
Definition gd.stub.php:796
imagegetclip(GdImage $image)
Definition gd.stub.php:726
imagepalettetotruecolor(GdImage $image)
Definition gd.stub.php:497
imagecolorresolvealpha(GdImage $image, int $red, int $green, int $blue, int $alpha)
Definition gd.stub.php:515
imageistruecolor(GdImage $image)
Definition gd.stub.php:493
imagecolorclosestalpha(GdImage $image, int $red, int $green, int $blue, int $alpha)
Definition gd.stub.php:517
imagegetinterpolation(GdImage $image)
Definition gd.stub.php:788
imagecreatefrombmp(string $filename)
Definition gd.stub.php:594
imageline(GdImage $image, int $x1, int $y1, int $x2, int $y2, int $color)
Definition gd.stub.php:668
imagegammacorrect(GdImage $image, float $input_gamma, float $output_gamma)
Definition gd.stub.php:664
imagesavealpha(GdImage $image, bool $enable)
Definition gd.stub.php:509
imagewebp(GdImage $image, $file=null, int $quality=-1)
Definition gd.stub.php:618
imagesetbrush(GdImage $image, GdImage $brush)
Definition gd.stub.php:538
imagefilledarc(GdImage $image, int $center_x, int $center_y, int $width, int $height, int $start_angle, int $end_angle, int $color, int $style)
Definition gd.stub.php:505
imagestring(GdImage $image, GdFont|int $font, int $x, int $y, string $string, int $color)
Definition gd.stub.php:704
imageaffinematrixget(int $type, $options)
Definition gd.stub.php:780
imageconvolution(GdImage $image, array $matrix, float $divisor, float $offset)
Definition gd.stub.php:757
imagecolorclosest(GdImage $image, int $red, int $green, int $blue)
Definition gd.stub.php:646
imagefilledellipse(GdImage $image, int $center_x, int $center_y, int $width, int $height, int $color)
Definition gd.stub.php:503
imagecrop(GdImage $image, array $rectangle)
Definition gd.stub.php:764
imagecreatefromxpm(string $filename)
Definition gd.stub.php:577
imagecopymergegray(GdImage $dst_image, GdImage $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $src_width, int $src_height, int $pct)
Definition gd.stub.php:712
imagefilltoborder(GdImage $image, int $x, int $y, int $border_color, int $color)
Definition gd.stub.php:680
#define GD_INFO
Definition gd_errors.h:24
#define GD_NOTICE
Definition gd_errors.h:23
#define GD_WARNING
Definition gd_errors.h:22
#define GD_DEBUG
Definition gd_errors.h:25
struct gdIOCtx * gdIOCtxPtr
Definition gd_io.h:25
#define SEEK_SET
Definition gd_io_file.c:20
#define NULL
Definition gdcache.h:45
gdFontPtr gdFontGiant
Definition gdfontg.c:4382
gdFontPtr gdFontLarge
Definition gdfontl.c:4639
gdFontPtr gdFontMediumBold
Definition gdfontmb.c:3869
gdFontPtr gdFontSmall
Definition gdfonts.c:3869
gdFontPtr gdFontTiny
Definition gdfontt.c:2590
#define C(x)
Definition hash_gost.c:111
#define SUCCESS
Definition hash_sha3.c:261
again j
foreach($dp as $el) foreach( $dp as $el) if( $pass2< 2) echo ""
PHPAPI const char php_sig_bmp[2]
Definition image.c:38
PHPAPI const char php_sig_png[8]
Definition image.c:42
bool php_is_image_avif(php_stream *stream)
Definition image.c:1204
PHPAPI const char php_sig_gif[3]
Definition image.c:36
PHPAPI const char php_sig_riff[4]
Definition image.c:52
PHPAPI const char php_sig_jpg[3]
Definition image.c:41
PHPAPI const char php_sig_webp[4]
Definition image.c:53
void gdImageSetTile(gdImagePtr im, gdImagePtr tile)
Definition gd.c:2887
void gdImageFilledPolygon(gdImagePtr im, gdPointPtr p, int n, int c)
Definition gd.c:2730
void gdImageRectangle(gdImagePtr im, int x1, int y1, int x2, int y2, int color)
Definition gd.c:2142
void gdImageCopyResized(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH)
Definition gd.c:2487
int gdImageColorAllocateAlpha(gdImagePtr im, int r, int g, int b, int a)
Definition gd.c:494
gdImagePtr gdImageCreate(int sx, int sy)
Definition gd.c:141
void gdImageAlphaBlending(gdImagePtr im, int alphaBlendingArg)
Definition gd.c:3037
void gdImageFilledRectangle(gdImagePtr im, int x1, int y1, int x2, int y2, int color)
Definition gd.c:2307
void gdImageSetBrush(gdImagePtr im, gdImagePtr brush)
Definition gd.c:2874
void gdImageLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color)
Definition gd.c:1096
void gdImageFilledArc(gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color, int style)
Definition gd.c:1650
void gdImageColorDeallocate(gdImagePtr im, int color)
Definition gd.c:597
void gdImageCharUp(gdImagePtr im, gdFontPtr f, int x, int y, int c, int color)
Definition gd.c:1545
int gdImageColorResolveAlpha(gdImagePtr im, int r, int g, int b, int a)
Definition gd.c:539
void gdImageOpenPolygon(gdImagePtr im, gdPointPtr p, int n, int c)
Definition gd.c:2701
int gdImageGetPixel(gdImagePtr im, int x, int y)
Definition gd.c:953
void gdImageSetAntiAliased(gdImagePtr im, int c)
Definition gd.c:2900
void gdImageDestroy(gdImagePtr im)
Definition gd.c:247
void gdImageSetClip(gdImagePtr im, int x1, int y1, int x2, int y2)
Definition gd.c:3102
void gdSetErrorMethod(gdErrorMethod error_method)
Definition gd.c:123
void gdImageFilledEllipse(gdImagePtr im, int mx, int my, int w, int h, int c)
Definition gd.c:1810
void gdImageFillToBorder(gdImagePtr im, int x, int y, int border, int color)
Definition gd.c:1858
int gdImageColorExact(gdImagePtr im, int r, int g, int b)
Definition gd.c:467
void gdImageArc(gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color)
Definition gd.c:1645
void gdImageSetThickness(gdImagePtr im, int thickness)
Definition gd.c:2869
int gdImageColorClosest(gdImagePtr im, int r, int g, int b)
Definition gd.c:271
void gdImageGetClip(gdImagePtr im, int *x1P, int *y1P, int *x2P, int *y2P)
Definition gd.c:3134
void gdImageSetResolution(gdImagePtr im, const unsigned int res_x, const unsigned int res_y)
Definition gd.c:3142
void gdImagePolygon(gdImagePtr im, gdPointPtr p, int n, int c)
Definition gd.c:2690
void gdImageEllipse(gdImagePtr im, int mx, int my, int w, int h, int c)
Definition gd.c:1771
void gdImageDashedLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color)
Definition gd.c:1376
void gdImageCopyResampled(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH)
Definition gd.c:2597
int gdImageColorExactAlpha(gdImagePtr im, int r, int g, int b, int a)
Definition gd.c:472
void gdImageSetStyle(gdImagePtr im, int *style, int noOfPixels)
Definition gd.c:2855
int gdImageColorResolve(gdImagePtr im, int r, int g, int b)
Definition gd.c:534
int gdImagePaletteToTrueColor(gdImagePtr src)
Definition gd.c:3149
int gdImageColorAllocate(gdImagePtr im, int r, int g, int b)
Definition gd.c:489
void gdImageCopyMerge(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h, int pct)
Definition gd.c:2393
void gdImageCopyMergeGray(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h, int pct)
Definition gd.c:2433
void gdImageFill(gdImagePtr im, int x, int y, int nc)
Definition gd.c:1970
void gdImageCopy(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h)
Definition gd.c:2312
void gdImagePaletteCopy(gdImagePtr to, gdImagePtr from)
Definition gd.c:624
void gdImageInterlace(gdImagePtr im, int interlaceArg)
Definition gd.c:2915
gdImagePtr gdImageCreateTrueColor(int sx, int sy)
Definition gd.c:195
int gdImageColorClosestAlpha(gdImagePtr im, int r, int g, int b, int a)
Definition gd.c:276
void gdImageColorTransparent(gdImagePtr im, int color)
Definition gd.c:606
void gdImageChar(gdImagePtr im, gdFontPtr f, int x, int y, int c, int color)
Definition gd.c:1517
void gdImageSetPixel(gdImagePtr im, int x, int y, int color)
Definition gd.c:733
int gdImageColorClosestHWB(gdImagePtr im, int r, int g, int b)
Definition gd.c:442
void gdImageSaveAlpha(gdImagePtr im, int saveAlphaArg)
Definition gd.c:3042
PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format,...)
Definition main.c:1173
PHPAPI size_t php_write(void *buf, size_t size)
Definition main.c:931
PHPAPI ZEND_COLD void php_verror(const char *docref, const char *params, int type, const char *format, va_list args)
Definition main.c:992
#define SH
Definition metaphone.c:60
php_info_print_table_start()
Definition info.c:1064
php_info_print_table_row(2, "PDO Driver for Firebird", "enabled")
php_info_print_table_end()
Definition info.c:1074
#define PHP_FUNCTION
Definition php.h:364
#define INT_MIN
Definition php.h:241
#define PHP_MSHUTDOWN_FUNCTION
Definition php.h:401
#define PHP_MINFO
Definition php.h:396
#define PHP_MINIT_FUNCTION
Definition php.h:400
#define PHP_MSHUTDOWN
Definition php.h:393
#define PHP_MINFO_FUNCTION
Definition php.h:404
#define INT_MAX
Definition php.h:237
#define PHP_RSHUTDOWN
Definition php.h:395
#define PHP_RSHUTDOWN_FUNCTION
Definition php.h:403
#define PHP_MINIT
Definition php.h:392
short color
#define PHP_INI_ALL
Definition php_ini.h:45
#define PHP_INI_BEGIN
Definition php_ini.h:52
#define PHP_INI_ENTRY_EX
Definition php_ini.h:61
#define PHP_INI_END
Definition php_ini.h:53
PHP_JSON_API size_t int options
Definition php_json.h:102
#define php_stream_memory_open(mode, str)
#define TEMP_STREAM_READONLY
PHPAPI FILE * php_open_temporary_file(const char *dir, const char *pfx, zend_string **opened_path_p)
unsigned char key[REFLECTION_KEY_LEN]
#define php_stream_cast(stream, as, ret, show_err)
#define PHP_STREAM_IS_STDIO
struct _php_stream php_stream
Definition php_streams.h:96
#define REPORT_ERRORS
#define php_stream_read(stream, buf, count)
#define IGNORE_PATH
#define PHP_STREAM_CAST_TRY_HARD
#define PHP_STREAM_COPY_ALL
#define php_stream_seek(stream, offset, whence)
#define php_stream_can_cast(stream, as)
#define php_stream_eof(stream)
#define php_stream_close(stream)
#define php_stream_is(stream, anops)
#define php_stream_tell(stream)
#define php_stream_copy_to_mem(src, maxlen, persistent)
#define php_stream_open_wrapper(path, mode, options, opened)
#define php_stream_from_zval_no_verify(xstr, pzval)
#define PHP_STREAM_AS_STDIO
#define php_stream_write(stream, buf, count)
const phpdbg_color_t * colors[PHPDBG_COLORS]
Definition phpdbg.h:295
zend_constant * data
#define SW
zend_object std
Definition gd.c:138
gdImagePtr image
Definition gd.c:137
gdFontPtr font
Definition gd.c:220
zend_object std
Definition gd.c:221
double linespacing
Definition gd.h:474
int flags
Definition gd.h:475
Definition gd.h:273
int offset
Definition gd.h:277
int w
Definition gd.h:279
int nchars
Definition gd.h:275
int h
Definition gd.h:280
char * data
Definition gd.h:284
void * data
Definition gd_io.h:22
void(* putC)(struct gdIOCtx *, int)
Definition gd_io.h:14
int(* getC)(struct gdIOCtx *)
Definition gd_io.h:11
int(* putBuf)(struct gdIOCtx *, const void *, int)
Definition gd_io.h:15
void(* gd_free)(struct gdIOCtx *)
Definition gd_io.h:20
int trueColor
Definition gd.h:217
int red[gdMaxColors]
Definition gd.h:179
unsigned char ** pixels
Definition gd.h:172
int blue[gdMaxColors]
Definition gd.h:181
int alpha[gdMaxColors]
Definition gd.h:214
int ** tpixels
Definition gd.h:218
gdInterpolationMethod interpolation_id
Definition gd.h:244
int AA
Definition gd.h:233
int green[gdMaxColors]
Definition gd.h:180
Definition gd.h:503
int x
Definition gd.h:504
int y
Definition gd.h:504
Definition gd.h:313
int x
Definition gd.h:314
int height
Definition gd.h:315
int y
Definition gd.h:314
int width
Definition gd.h:315
$obj a
Definition test.php:84
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format,...)
Definition zend.c:1772
ZEND_API ZEND_COLD void zend_value_error(const char *format,...)
Definition zend.c:1849
#define INTERNAL_FUNCTION_PARAMETERS
Definition zend.h:49
#define INTERNAL_FUNCTION_PARAM_PASSTHRU
Definition zend.h:50
ZEND_API const char * zend_zval_value_name(const zval *arg)
Definition zend_API.c:148
ZEND_API zend_result add_next_index_long(zval *arg, zend_long n)
Definition zend_API.c:2132
ZEND_API zend_result object_init_ex(zval *arg, zend_class_entry *class_type)
Definition zend_API.c:1849
ZEND_API void add_index_double(zval *arg, zend_ulong index, double d)
Definition zend_API.c:2069
ZEND_API zend_result zend_parse_parameters(uint32_t num_args, const char *type_spec,...)
Definition zend_API.c:1300
ZEND_API void object_properties_init(zend_object *object, zend_class_entry *class_type)
Definition zend_API.c:1688
ZEND_API ZEND_COLD void zend_argument_must_not_be_empty_error(uint32_t arg_num)
Definition zend_API.c:443
ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *format,...)
Definition zend_API.c:433
ZEND_API ZEND_COLD void zend_argument_type_error(uint32_t arg_num, const char *format,...)
Definition zend_API.c:423
#define Z_PARAM_PATH_STR(dest)
Definition zend_API.h:2041
#define ZEND_NUM_ARGS()
Definition zend_API.h:530
#define Z_PARAM_PATH_OR_NULL(dest, dest_len)
Definition zend_API.h:2029
#define Z_PARAM_ARRAY_OR_NULL(dest)
Definition zend_API.h:1685
#define ZEND_PARSE_PARAMETERS_END()
Definition zend_API.h:1641
#define RETURN_FALSE
Definition zend_API.h:1058
#define ZEND_PARSE_PARAMETERS_NONE()
Definition zend_API.h:1623
#define Z_PARAM_OPTIONAL
Definition zend_API.h:1667
#define ZEND_GET_MODULE(name)
Definition zend_API.h:241
#define Z_PARAM_STR(dest)
Definition zend_API.h:2086
#define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args)
Definition zend_API.h:1620
#define Z_PARAM_BOOL_OR_NULL(dest, is_null)
Definition zend_API.h:1729
#define Z_PARAM_LONG(dest)
Definition zend_API.h:1896
#define RETURN_LONG(l)
Definition zend_API.h:1037
#define RETURN_BOOL(b)
Definition zend_API.h:1035
#define RETURN_THROWS()
Definition zend_API.h:1060
#define Z_PARAM_DOUBLE(dest)
Definition zend_API.h:1803
#define RETVAL_BOOL(b)
Definition zend_API.h:1009
#define CHECK_ZVAL_NULL_PATH(p)
Definition zend_API.h:949
#define Z_PARAM_LONG_OR_NULL(dest, is_null)
Definition zend_API.h:1899
#define Z_PARAM_BOOL(dest)
Definition zend_API.h:1726
#define Z_PARAM_OBJECT_OF_CLASS(dest, _ce)
Definition zend_API.h:1976
#define Z_PARAM_ARRAY(dest)
Definition zend_API.h:1682
#define Z_PARAM_ZVAL_OR_NULL(dest)
Definition zend_API.h:2103
#define Z_PARAM_ZVAL(dest)
Definition zend_API.h:2100
#define Z_PARAM_OBJ_OF_CLASS_OR_LONG(dest_obj, _ce, dest_long)
Definition zend_API.h:2011
#define WRONG_PARAM_COUNT
Definition zend_API.h:529
#define RETURN_TRUE
Definition zend_API.h:1059
#define array_init(arg)
Definition zend_API.h:537
#define estrndup(s, length)
Definition zend_alloc.h:165
#define ecalloc(nmemb, size)
Definition zend_alloc.h:158
#define pestrndup(s, length, persistent)
Definition zend_alloc.h:207
#define efree(ptr)
Definition zend_alloc.h:155
#define pefree(ptr, persistent)
Definition zend_alloc.h:191
#define safe_emalloc(nmemb, size, offset)
Definition zend_alloc.h:154
#define emalloc(size)
Definition zend_alloc.h:151
struct _zval_struct zval
strlen(string $string)
zend_string_release_ex(func->internal_function.function_name, 0)
zval * args
#define snprintf
#define E_NOTICE
Definition zend_errors.h:26
#define E_ERROR
Definition zend_errors.h:23
#define E_WARNING
Definition zend_errors.h:24
#define E_DEPRECATED
Definition zend_errors.h:37
ZEND_API void(ZEND_FASTCALL *zend_touch_vm_stack_data)(void *vm_stack_data)
union _zend_function zend_function
ZEND_API zval *ZEND_FASTCALL zend_hash_str_find(const HashTable *ht, const char *str, size_t len)
Definition zend_hash.c:2689
ZEND_API zval *ZEND_FASTCALL zend_hash_index_find(const HashTable *ht, zend_ulong h)
Definition zend_hash.c:2701
#define HT_IS_PACKED(ht)
Definition zend_hash.h:59
#define ZEND_HASH_FOREACH_END()
Definition zend_hash.h:1086
#define ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(ht, _key, _val)
Definition zend_hash.h:1374
#define ZEND_HASH_FOREACH_VAL(ht, _val)
Definition zend_hash.h:1102
#define UNREGISTER_INI_ENTRIES()
Definition zend_ini.h:204
#define REGISTER_INI_ENTRIES()
Definition zend_ini.h:203
#define DISPLAY_INI_ENTRIES()
Definition zend_ini.h:205
#define INI_INT(name)
Definition zend_ini.h:193
int32_t zend_long
Definition zend_long.h:42
#define ZEND_LONG_FMT
Definition zend_long.h:87
struct _zend_string zend_string
#define STANDARD_MODULE_HEADER
struct _zend_module_entry zend_module_entry
#define STANDARD_MODULE_PROPERTIES
ZEND_API int zend_objects_not_comparable(zval *o1, zval *o2)
ZEND_API const zend_object_handlers std_object_handlers
ZEND_API void ZEND_FASTCALL zend_object_std_init(zend_object *object, zend_class_entry *ce)
ZEND_API void zend_object_std_dtor(zend_object *object)
#define zend_finite(a)
#define LONG_MAX
#define zend_always_inline
#define XtOffsetOf(s_type, field)
#define ZEND_ASSERT(c)
#define EMPTY_SWITCH_DEFAULT_CASE()
#define UNEXPECTED(condition)
#define LONG_MIN
struct _zend_class_entry zend_class_entry
struct _zend_object zend_object
#define ZEND_SIZE_T_UINT_OVFL(size)
#define ZEND_LONG_INT_OVFL(zlong)
#define ZEND_SIZE_T_INT_OVFL(size)
#define ZSTR_VAL(zstr)
Definition zend_string.h:68
#define zend_string_equals_literal(str, literal)
#define ZSTR_LEN(zstr)
Definition zend_string.h:69
#define Z_TYPE_P(zval_p)
Definition zend_types.h:660
#define Z_STRVAL_P(zval_p)
Definition zend_types.h:975
#define Z_ARRVAL_P(zval_p)
Definition zend_types.h:987
#define IS_STRING
Definition zend_types.h:606
#define IS_RESOURCE
Definition zend_types.h:609
#define Z_OBJ_P(zval_p)
Definition zend_types.h:990
#define IS_ARRAY
Definition zend_types.h:607
#define IS_DOUBLE
Definition zend_types.h:605
@ FAILURE
Definition zend_types.h:61
#define IS_LONG
Definition zend_types.h:604
struct _zend_object_handlers zend_object_handlers
Definition zend_types.h:88
#define Z_DVAL_P(zval_p)
Definition zend_types.h:969
#define Z_LVAL_P(zval_p)
Definition zend_types.h:966
#define VCWD_FOPEN(path, mode)
#define VCWD_UNLINK(path)
#define MAXPATHLEN
#define VCWD_REALPATH(path, real_path)
zval * return_value
uint32_t arg_num
bool result
zval * ret
zend_object * zobj