Skip to content

Commit c1d1c7a

Browse files
committed
Alias gd functions
1 parent 582acad commit c1d1c7a

File tree

4 files changed

+73
-58
lines changed

4 files changed

+73
-58
lines changed

ext/gd/gd.c

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static int le_gd_font;
8686
#endif
8787

8888
#ifdef HAVE_GD_FREETYPE
89-
static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int, int);
89+
static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int);
9090
#endif
9191

9292
#include "gd_arginfo.h"
@@ -3099,33 +3099,19 @@ PHP_FUNCTION(imagegetclip)
30993099
/* {{{ Give the bounding box of a text using fonts via freetype2 */
31003100
PHP_FUNCTION(imageftbbox)
31013101
{
3102-
php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_BBOX, 1);
3102+
php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_BBOX);
31033103
}
31043104
/* }}} */
31053105

31063106
/* {{{ Write text to the image using fonts via freetype2 */
31073107
PHP_FUNCTION(imagefttext)
31083108
{
3109-
php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_DRAW, 1);
3110-
}
3111-
/* }}} */
3112-
3113-
/* {{{ Give the bounding box of a text using TrueType fonts */
3114-
PHP_FUNCTION(imagettfbbox)
3115-
{
3116-
php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_BBOX, 0);
3117-
}
3118-
/* }}} */
3119-
3120-
/* {{{ Write text to the image using a TrueType font */
3121-
PHP_FUNCTION(imagettftext)
3122-
{
3123-
php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_DRAW, 0);
3109+
php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_DRAW);
31243110
}
31253111
/* }}} */
31263112

31273113
/* {{{ php_imagettftext_common */
3128-
static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int extended)
3114+
static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode)
31293115
{
31303116
zval *IM, *EXT = NULL;
31313117
gdImagePtr im=NULL;
@@ -3138,15 +3124,11 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int
31383124
gdFTStringExtra strex = {0};
31393125

31403126
if (mode == TTFTEXT_BBOX) {
3141-
if (extended && zend_parse_parameters(ZEND_NUM_ARGS(), "ddss|a!", &ptsize, &angle, &fontname, &fontname_len, &str, &str_len, &EXT) == FAILURE) {
3142-
RETURN_THROWS();
3143-
} else if (zend_parse_parameters(ZEND_NUM_ARGS(), "ddss", &ptsize, &angle, &fontname, &fontname_len, &str, &str_len) == FAILURE) {
3127+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ddss|a", &ptsize, &angle, &fontname, &fontname_len, &str, &str_len, &EXT) == FAILURE) {
31443128
RETURN_THROWS();
31453129
}
31463130
} else {
3147-
if (extended && 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) {
3148-
RETURN_THROWS();
3149-
} else if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oddlllss", &IM, gd_image_ce, &ptsize, &angle, &x, &y, &col, &fontname, &fontname_len, &str, &str_len) == FAILURE) {
3131+
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) {
31503132
RETURN_THROWS();
31513133
}
31523134
im = php_gd_libgdimageptr_from_zval_p(IM);
@@ -3155,7 +3137,7 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int
31553137
/* convert angle to radians */
31563138
angle = angle * (M_PI/180);
31573139

3158-
if (extended && EXT) { /* parse extended info */
3140+
if (EXT) { /* parse extended info */
31593141
zval *item;
31603142
zend_string *key;
31613143

@@ -3183,7 +3165,7 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int
31833165

31843166
PHP_GD_CHECK_OPEN_BASEDIR(fontname, "Invalid font filename");
31853167

3186-
if (extended) {
3168+
if (EXT) {
31873169
error = gdImageStringFTEx(im, brect, col, fontname, ptsize, angle, x, y, str, &strex);
31883170
} else {
31893171
error = gdImageStringFT(im, brect, col, fontname, ptsize, angle, x, y, str);

ext/gd/gd.stub.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,15 @@ function imagesetclip(GdImage $im, int $x1, int $x2, int $y1, int $y2): bool {}
215215
function imagegetclip(GdImage $im): array {}
216216

217217
#ifdef HAVE_GD_FREETYPE
218-
function imageftbbox(float $size, float $angle, string $font_file, string $text, ?array $extrainfo = null): array|false {}
218+
function imageftbbox(float $size, float $angle, string $font_file, string $text, array $extrainfo = []): array|false {}
219219

220-
function imagefttext(GdImage $im, float $size, float $angle, int $x, int $y, int $col, string $font_file, string $text, ?array $extrainfo = null): array|false {}
220+
function imagefttext(GdImage $im, float $size, float $angle, int $x, int $y, int $col, string $font_file, string $text, array $extrainfo = []): array|false {}
221221

222-
function imagettfbbox(float $size, float $angle, string $font_file, string $text): array|false {}
222+
/** @alias imagetfbbox */
223+
function imagettfbbox(float $size, float $angle, string $font_file, string $text, array $extrainfo = []): array|false {}
223224

224-
function imagettftext(GdImage $im, float $size, float $angle, int $x, int $y, int $col, string $font_file, string $text): array|false {}
225+
/** @alias imageftext */
226+
function imagettftext(GdImage $im, float $size, float $angle, int $x, int $y, int $col, string $font_file, string $text, array $extrainfo = []): array|false {}
225227
#endif
226228

227229
/** @param array|int|float|bool $filter_args */

ext/gd/gd_arginfo.h

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 0fa62602a13cbcdcabfd37d6ffc6f5079eeb0838 */
2+
* Stub hash: ab292e3981e82aa97a0833b6affc1267bc12e518 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gd_info, 0, 0, IS_ARRAY, 0)
55
ZEND_END_ARG_INFO()
@@ -459,7 +459,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imageftbbox, 0, 4, MAY_BE_ARRAY|
459459
ZEND_ARG_TYPE_INFO(0, angle, IS_DOUBLE, 0)
460460
ZEND_ARG_TYPE_INFO(0, font_file, IS_STRING, 0)
461461
ZEND_ARG_TYPE_INFO(0, text, IS_STRING, 0)
462-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, extrainfo, IS_ARRAY, 1, "null")
462+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, extrainfo, IS_ARRAY, 0, "[]")
463463
ZEND_END_ARG_INFO()
464464
#endif
465465

@@ -473,30 +473,16 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imagefttext, 0, 8, MAY_BE_ARRAY|
473473
ZEND_ARG_TYPE_INFO(0, col, IS_LONG, 0)
474474
ZEND_ARG_TYPE_INFO(0, font_file, IS_STRING, 0)
475475
ZEND_ARG_TYPE_INFO(0, text, IS_STRING, 0)
476-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, extrainfo, IS_ARRAY, 1, "null")
476+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, extrainfo, IS_ARRAY, 0, "[]")
477477
ZEND_END_ARG_INFO()
478478
#endif
479479

480480
#if defined(HAVE_GD_FREETYPE)
481-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imagettfbbox, 0, 4, MAY_BE_ARRAY|MAY_BE_FALSE)
482-
ZEND_ARG_TYPE_INFO(0, size, IS_DOUBLE, 0)
483-
ZEND_ARG_TYPE_INFO(0, angle, IS_DOUBLE, 0)
484-
ZEND_ARG_TYPE_INFO(0, font_file, IS_STRING, 0)
485-
ZEND_ARG_TYPE_INFO(0, text, IS_STRING, 0)
486-
ZEND_END_ARG_INFO()
481+
#define arginfo_imagettfbbox arginfo_imageftbbox
487482
#endif
488483

489484
#if defined(HAVE_GD_FREETYPE)
490-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imagettftext, 0, 8, MAY_BE_ARRAY|MAY_BE_FALSE)
491-
ZEND_ARG_OBJ_INFO(0, im, GdImage, 0)
492-
ZEND_ARG_TYPE_INFO(0, size, IS_DOUBLE, 0)
493-
ZEND_ARG_TYPE_INFO(0, angle, IS_DOUBLE, 0)
494-
ZEND_ARG_TYPE_INFO(0, x, IS_LONG, 0)
495-
ZEND_ARG_TYPE_INFO(0, y, IS_LONG, 0)
496-
ZEND_ARG_TYPE_INFO(0, col, IS_LONG, 0)
497-
ZEND_ARG_TYPE_INFO(0, font_file, IS_STRING, 0)
498-
ZEND_ARG_TYPE_INFO(0, text, IS_STRING, 0)
499-
ZEND_END_ARG_INFO()
485+
#define arginfo_imagettftext arginfo_imagefttext
500486
#endif
501487

502488
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagefilter, 0, 2, _IS_BOOL, 0)
@@ -691,10 +677,10 @@ ZEND_FUNCTION(imageftbbox);
691677
ZEND_FUNCTION(imagefttext);
692678
#endif
693679
#if defined(HAVE_GD_FREETYPE)
694-
ZEND_FUNCTION(imagettfbbox);
680+
ZEND_FUNCTION(imagetfbbox);
695681
#endif
696682
#if defined(HAVE_GD_FREETYPE)
697-
ZEND_FUNCTION(imagettftext);
683+
ZEND_FUNCTION(imageftext);
698684
#endif
699685
ZEND_FUNCTION(imagefilter);
700686
ZEND_FUNCTION(imageconvolution);
@@ -832,10 +818,10 @@ static const zend_function_entry ext_functions[] = {
832818
ZEND_FE(imagefttext, arginfo_imagefttext)
833819
#endif
834820
#if defined(HAVE_GD_FREETYPE)
835-
ZEND_FE(imagettfbbox, arginfo_imagettfbbox)
821+
ZEND_FALIAS(imagettfbbox, imagetfbbox, arginfo_imagettfbbox)
836822
#endif
837823
#if defined(HAVE_GD_FREETYPE)
838-
ZEND_FE(imagettftext, arginfo_imagettftext)
824+
ZEND_FALIAS(imagettftext, imageftext, arginfo_imagettftext)
839825
#endif
840826
ZEND_FE(imagefilter, arginfo_imagefilter)
841827
ZEND_FE(imageconvolution, arginfo_imageconvolution)

ext/gd/tests/bug67248.phpt

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,60 @@ require __DIR__ . '/func.inc';
1111

1212
for($i=0;$i<7;$i++) {
1313
trycatch_dump(
14-
fn() => imageaffinematrixget($i)
14+
fn() => imageaffinematrixget($i, new stdClass())
1515
);
1616
}
1717
?>
18-
--EXPECT--
18+
--EXPECTF--
1919
!! [TypeError] imageaffinematrixget(): Argument #1 ($type) must be of type array when using translate or scale
2020
!! [TypeError] imageaffinematrixget(): Argument #1 ($type) must be of type array when using translate or scale
21-
!! [TypeError] imageaffinematrixget(): Argument #2 ($options) must be of type int|float when using rotate or shear
22-
!! [TypeError] imageaffinematrixget(): Argument #2 ($options) must be of type int|float when using rotate or shear
23-
!! [TypeError] imageaffinematrixget(): Argument #2 ($options) must be of type int|float when using rotate or shear
21+
22+
Notice: Object of class stdClass could not be converted to float in %s on line %d
23+
array(6) {
24+
[0]=>
25+
float(%f)
26+
[1]=>
27+
float(%f)
28+
[2]=>
29+
float(%f)
30+
[3]=>
31+
float(%f)
32+
[4]=>
33+
float(0)
34+
[5]=>
35+
float(0)
36+
}
37+
38+
Notice: Object of class stdClass could not be converted to float in %s on line %d
39+
array(6) {
40+
[0]=>
41+
float(1)
42+
[1]=>
43+
float(0)
44+
[2]=>
45+
float(%f)
46+
[3]=>
47+
float(1)
48+
[4]=>
49+
float(0)
50+
[5]=>
51+
float(0)
52+
}
53+
54+
Notice: Object of class stdClass could not be converted to float in %s on line %d
55+
array(6) {
56+
[0]=>
57+
float(1)
58+
[1]=>
59+
float(%f)
60+
[2]=>
61+
float(0)
62+
[3]=>
63+
float(1)
64+
[4]=>
65+
float(0)
66+
[5]=>
67+
float(0)
68+
}
2469
!! [ValueError] imageaffinematrixget(): Argument #1 ($type) must be a valid element type
2570
!! [ValueError] imageaffinematrixget(): Argument #1 ($type) must be a valid element type

0 commit comments

Comments
 (0)