Skip to content

Commit 31d85b8

Browse files
committed
cleanup gd build with system libgd - drop need to use libpng with system libgd - drop need to use libjpeg with system libgd - drop need to use libXpm with system libgd - drop need to use libfreetype with system libgd - improve configure comments
1 parent a2b758d commit 31d85b8

File tree

5 files changed

+30
-91
lines changed

5 files changed

+30
-91
lines changed

ext/gd/config.m4

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if test -z "$PHP_WEBP"; then
1717
PHP_ARG_WITH([webp],
1818
[for libwebp],
1919
[AS_HELP_STRING([--with-webp],
20-
[GD: Enable WEBP support])],
20+
[GD: Enable WEBP support (only for bundled libgd)])],
2121
[no],
2222
[no])
2323
fi
@@ -26,29 +26,29 @@ if test -z "$PHP_JPEG"; then
2626
PHP_ARG_WITH([jpeg],
2727
[for libjpeg],
2828
[AS_HELP_STRING([--with-jpeg],
29-
[GD: Enable JPEG support])],
29+
[GD: Enable JPEG support (only for bundled libgd)])],
3030
[no],
3131
[no])
3232
fi
3333

3434
PHP_ARG_WITH([xpm],
3535
[for libXpm],
3636
[AS_HELP_STRING([--with-xpm],
37-
[GD: Enable XPM support])],
37+
[GD: Enable XPM support (only for bundled libgd)])],
3838
[no],
3939
[no])
4040

4141
PHP_ARG_WITH([freetype],
4242
[for FreeType 2],
4343
[AS_HELP_STRING([--with-freetype],
44-
[GD: Enable FreeType 2 support])],
44+
[GD: Enable FreeType 2 support (only for bundled libgd)])],
4545
[no],
4646
[no])
4747

4848
PHP_ARG_ENABLE([gd-jis-conv],
4949
[whether to enable JIS-mapped Japanese font support in GD],
5050
[AS_HELP_STRING([--enable-gd-jis-conv],
51-
[GD: Enable JIS-mapped Japanese font support])],
51+
[GD: Enable JIS-mapped Japanese font support (only for bundled libgd)])],
5252
[no],
5353
[no])
5454

@@ -176,15 +176,6 @@ dnl Various checks for GD features
176176
], [ $GD_SHARED_LIBADD ], [char foobar () {}])
177177

178178
else
179-
dnl for png.h in gd_compat (PNG_LIBPNG_VER_STRING)
180-
PHP_GD_PNG
181-
dnl for jpeglib.h in gd_compat (JPEG_LIB_VERSION)
182-
PHP_GD_JPEG
183-
dnl for X11/xpm.h in gd.c (XpmLibraryVersion)
184-
PHP_GD_XPM
185-
dnl for ft2build.h in gd.c (FREETYPE_MAJOR...)
186-
PHP_GD_FREETYPE2
187-
188179
extra_sources="gd_compat.c"
189180
PKG_CHECK_MODULES([GDLIB], [gdlib >= 2.1.0])
190181
PHP_EVAL_LIBLINE($GDLIB_LIBS, GD_SHARED_LIBADD)

ext/gd/gd.c

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
#include "php_open_temporary_file.h"
3838

3939

40-
#if HAVE_SYS_WAIT_H
40+
#ifdef HAVE_SYS_WAIT_H
4141
# include <sys/wait.h>
4242
#endif
43-
#if HAVE_UNISTD_H
43+
#ifdef HAVE_UNISTD_H
4444
# include <unistd.h>
4545
#endif
4646
#ifdef PHP_WIN32
@@ -51,7 +51,7 @@
5151
# include <Wingdi.h>
5252
#endif
5353

54-
#ifdef HAVE_GD_XPM
54+
#if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
5555
# include <X11/xpm.h>
5656
#endif
5757

@@ -68,7 +68,7 @@ static int le_gd, le_gd_font;
6868
#include <gdfontl.h> /* 4 Large font */
6969
#include <gdfontg.h> /* 5 Giant font */
7070

71-
#if HAVE_LIBFREETYPE
71+
#if defined(HAVE_GD_FREETYPE) && defined(HAVE_GD_BUNDLED)
7272
# include <ft2build.h>
7373
# include FT_FREETYPE_H
7474
#endif
@@ -81,7 +81,7 @@ static int le_gd, le_gd_font;
8181
#define M_PI 3.14159265358979323846
8282
#endif
8383

84-
#if HAVE_LIBFREETYPE
84+
#ifdef HAVE_GD_FREETYPE
8585
static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int, int);
8686
#endif
8787

@@ -722,7 +722,7 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagegetclip, 0)
722722
ZEND_ARG_INFO(0, im)
723723
ZEND_END_ARG_INFO()
724724

725-
#if HAVE_LIBFREETYPE
725+
#ifdef HAVE_GD_FREETYPE
726726
ZEND_BEGIN_ARG_INFO_EX(arginfo_imageftbbox, 0, 0, 4)
727727
ZEND_ARG_INFO(0, size)
728728
ZEND_ARG_INFO(0, angle)
@@ -987,13 +987,11 @@ static const zend_function_entry gd_functions[] = {
987987
PHP_FE(imagegetclip, arginfo_imagegetclip)
988988
PHP_FE(imagedashedline, arginfo_imagedashedline)
989989

990-
#if HAVE_LIBFREETYPE
990+
#ifdef HAVE_GD_FREETYPE
991991
PHP_FE(imagettfbbox, arginfo_imagettfbbox)
992992
PHP_FE(imagettftext, arginfo_imagettftext)
993-
#if HAVE_GD_FREETYPE && HAVE_LIBFREETYPE
994993
PHP_FE(imageftbbox, arginfo_imageftbbox)
995994
PHP_FE(imagefttext, arginfo_imagefttext)
996-
#endif
997995
#endif
998996

999997
PHP_FE(imagetypes, arginfo_imagetypes)
@@ -1027,11 +1025,7 @@ zend_module_entry gd_module_entry = {
10271025
PHP_MINIT(gd),
10281026
PHP_MSHUTDOWN(gd),
10291027
NULL,
1030-
#if HAVE_GD_FREETYPE && HAVE_LIBFREETYPE
10311028
PHP_RSHUTDOWN(gd),
1032-
#else
1033-
NULL,
1034-
#endif
10351029
PHP_MINFO(gd),
10361030
PHP_GD_VERSION,
10371031
STANDARD_MODULE_PROPERTIES
@@ -1099,7 +1093,7 @@ PHP_MINIT_FUNCTION(gd)
10991093
le_gd = zend_register_list_destructors_ex(php_free_gd_image, NULL, "gd", module_number);
11001094
le_gd_font = zend_register_list_destructors_ex(php_free_gd_font, NULL, "gd font", module_number);
11011095

1102-
#if HAVE_GD_BUNDLED && HAVE_LIBFREETYPE
1096+
#if defined(HAVE_GD_FREETYPE) && defined(HAVE_GD_BUNDLED)
11031097
gdFontCacheMutexSetup();
11041098
#endif
11051099
gdSetErrorMethod(php_gd_error_method);
@@ -1238,7 +1232,7 @@ PHP_MINIT_FUNCTION(gd)
12381232
*/
12391233
PHP_MSHUTDOWN_FUNCTION(gd)
12401234
{
1241-
#if HAVE_GD_BUNDLED && HAVE_LIBFREETYPE
1235+
#if defined(HAVE_GD_FREETYPE) && defined(HAVE_GD_BUNDLED)
12421236
gdFontCacheMutexShutdown();
12431237
#endif
12441238
return SUCCESS;
@@ -1247,13 +1241,13 @@ PHP_MSHUTDOWN_FUNCTION(gd)
12471241

12481242
/* {{{ PHP_RSHUTDOWN_FUNCTION
12491243
*/
1250-
#if HAVE_GD_FREETYPE && HAVE_LIBFREETYPE
12511244
PHP_RSHUTDOWN_FUNCTION(gd)
12521245
{
1246+
#ifdef HAVE_GD_FREETYPE
12531247
gdFontCacheShutdown();
1248+
#endif
12541249
return SUCCESS;
12551250
}
1256-
#endif
12571251
/* }}} */
12581252

12591253
#if defined(HAVE_GD_BUNDLED)
@@ -1280,9 +1274,10 @@ PHP_MINFO_FUNCTION(gd)
12801274
#endif
12811275
#endif
12821276

1283-
#if HAVE_LIBFREETYPE
1277+
#ifdef HAVE_GD_FREETYPE
12841278
php_info_print_table_row(2, "FreeType Support", "enabled");
12851279
php_info_print_table_row(2, "FreeType Linkage", "with freetype");
1280+
#ifdef HAVE_GD_BUNDLED
12861281
{
12871282
char tmp[256];
12881283

@@ -1295,6 +1290,7 @@ PHP_MINFO_FUNCTION(gd)
12951290
#endif
12961291
php_info_print_table_row(2, "FreeType Version", tmp);
12971292
}
1293+
#endif
12981294
#endif
12991295

13001296
php_info_print_table_row(2, "GIF Read Support", "enabled");
@@ -1303,22 +1299,28 @@ PHP_MINFO_FUNCTION(gd)
13031299
#ifdef HAVE_GD_JPG
13041300
{
13051301
php_info_print_table_row(2, "JPEG Support", "enabled");
1302+
#if defined(HAVE_GD_BUNDLED)
13061303
php_info_print_table_row(2, "libJPEG Version", gdJpegGetVersionString());
1304+
#endif
13071305
}
13081306
#endif
13091307

13101308
#ifdef HAVE_GD_PNG
13111309
php_info_print_table_row(2, "PNG Support", "enabled");
1310+
#if defined(HAVE_GD_BUNDLED)
13121311
php_info_print_table_row(2, "libPNG Version", gdPngGetVersionString());
1312+
#endif
13131313
#endif
13141314
php_info_print_table_row(2, "WBMP Support", "enabled");
13151315
#if defined(HAVE_GD_XPM)
13161316
php_info_print_table_row(2, "XPM Support", "enabled");
1317+
#if defined(HAVE_GD_BUNDLED)
13171318
{
13181319
char tmp[12];
13191320
snprintf(tmp, sizeof(tmp), "%d", XpmLibraryVersion());
13201321
php_info_print_table_row(2, "libXpm Version", tmp);
13211322
}
1323+
#endif
13221324
#endif
13231325
php_info_print_table_row(2, "XBM Support", "enabled");
13241326
#if defined(USE_GD_JISX0208)
@@ -1350,7 +1352,7 @@ PHP_FUNCTION(gd_info)
13501352

13511353
add_assoc_string(return_value, "GD Version", PHP_GD_VERSION_STRING);
13521354

1353-
#if HAVE_LIBFREETYPE
1355+
#ifdef HAVE_GD_FREETYPE
13541356
add_assoc_bool(return_value, "FreeType Support", 1);
13551357
add_assoc_string(return_value, "FreeType Linkage", "with freetype");
13561358
#else
@@ -3965,14 +3967,10 @@ PHP_FUNCTION(imagegetclip)
39653967
}
39663968
/* }}} */
39673969

3968-
#if HAVE_LIBFREETYPE
39693970
#define TTFTEXT_DRAW 0
39703971
#define TTFTEXT_BBOX 1
3971-
#endif
3972-
3973-
#if HAVE_LIBFREETYPE
39743972

3975-
#if HAVE_GD_FREETYPE
3973+
#ifdef HAVE_GD_FREETYPE
39763974
/* {{{ proto array imageftbbox(float size, float angle, string font_file, string text [, array extrainfo])
39773975
Give the bounding box of a text using fonts via freetype2 */
39783976
PHP_FUNCTION(imageftbbox)
@@ -3988,7 +3986,6 @@ PHP_FUNCTION(imagefttext)
39883986
php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_DRAW, 1);
39893987
}
39903988
/* }}} */
3991-
#endif /* HAVE_GD_FREETYPE */
39923989

39933990
/* {{{ proto array imagettfbbox(float size, float angle, string font_file, string text)
39943991
Give the bounding box of a text using TrueType fonts */
@@ -4069,14 +4066,11 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int
40694066

40704067
PHP_GD_CHECK_OPEN_BASEDIR(fontname, "Invalid font filename");
40714068

4072-
#ifdef HAVE_GD_FREETYPE
40734069
if (extended) {
40744070
error = gdImageStringFTEx(im, brect, col, fontname, ptsize, angle, x, y, str, &strex);
4075-
}
4076-
else
4071+
} else {
40774072
error = gdImageStringFT(im, brect, col, fontname, ptsize, angle, x, y, str);
4078-
4079-
#endif /* HAVE_GD_FREETYPE */
4073+
}
40804074

40814075
if (error) {
40824076
php_error_docref(NULL, E_WARNING, "%s", error);
@@ -4091,7 +4085,7 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int
40914085
}
40924086
}
40934087
/* }}} */
4094-
#endif /* HAVE_LIBFREETYPE */
4088+
#endif /* HAVE_GD_FREETYPE */
40954089

40964090
/* {{{ proto bool image2wbmp(resource im [, string filename [, int foreground]])
40974091
Output WBMP image to browser or file */

ext/gd/gd_compat.c

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,9 @@
44
#include "php_config.h"
55
#endif
66

7-
#ifdef HAVE_GD_PNG
8-
/* needs to be first */
9-
# include <png.h>
10-
#endif
11-
12-
#ifdef HAVE_GD_JPG
13-
# include <jpeglib.h>
14-
#endif
15-
167
#include "gd_compat.h"
178
#include "php.h"
189

19-
#ifdef HAVE_GD_JPG
20-
const char * gdJpegGetVersionString()
21-
{
22-
switch(JPEG_LIB_VERSION) {
23-
case 62:
24-
return "6b";
25-
break;
26-
27-
case 70:
28-
return "7";
29-
break;
30-
31-
case 80:
32-
return "8";
33-
break;
34-
35-
default:
36-
return "unknown";
37-
}
38-
}
39-
#endif
40-
41-
#ifdef HAVE_GD_PNG
42-
const char * gdPngGetVersionString()
43-
{
44-
return PNG_LIBPNG_VER_STRING;
45-
}
46-
#endif
47-
4810
int overflow2(int a, int b)
4911
{
5012

ext/gd/gd_compat.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
#ifndef GD_COMPAT_H
22
#define GD_COMPAT_H 1
33

4-
#ifndef HAVE_GD_BUNDLED
5-
/* from gd_compat.c */
6-
const char * gdPngGetVersionString();
7-
const char * gdJpegGetVersionString();
8-
#endif
9-
104
/* from gd_compat.c of libgd/gd_security.c */
115
int overflow2(int a, int b);
126

ext/gd/php_gd.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ extern zend_module_entry gd_module_entry;
7878
PHP_MINFO_FUNCTION(gd);
7979
PHP_MINIT_FUNCTION(gd);
8080
PHP_MSHUTDOWN_FUNCTION(gd);
81-
#if HAVE_GD_FREETYPE && HAVE_LIBFREETYPE
8281
PHP_RSHUTDOWN_FUNCTION(gd);
83-
#endif
8482

8583
PHP_FUNCTION(gd_info);
8684
PHP_FUNCTION(imagearc);

0 commit comments

Comments
 (0)