Dealing with Changes to the GD Extension
Learn about the functions that produce objects instead of resources and other updates to GD extension in PHP 8.
We'll cover the following
The GD (Graphics Draw) extension is an image manipulation extension that leverages the GD library. GD originally stood for GIF Draw. Oddly, the GD library had to withdraw support for the Graphics Interchange Format (GIF) after Unisys revoked the open-source license for the compression technology used when generating GIFs. After 2004, however, the Unisys patent on this technology expired and GIF support was restored. As it stands today, the GD extension offers support for the Joint Photographic Experts Group (JPEG or JPG), Portable Network Graphic (PNG), GIF, X BitMap (XBM), X PixMap (XPM), Wireless Bitmap (WBMP), WebP, and Bitmap (BMP) formats.
Let’s now have a look at the impact of resource-to-object migration on the GD extension.
GD extension resource-to-object migration
As with other PHP extensions that previously used resources, the GD
extension has also primarily migrated from resource
to object
. All of the imagecreate*()
functions now produce GdImage
objects rather than resources.
We now turn our attention to other GD extension changes.
GD extension compile flag changes
The GD
extension not only leverages the GD library but a number of supporting libraries as well. These libraries are needed to provide support for the various graphics formats. Previously, when compiling a custom version of PHP from the source code, we needed to specify the location of the libraries for JPEG, PNG, XPM, and VPX formats. In addition, because compression is an important aspect in reducing the overall final file size, the location of ZLIB
was needed as well.
When compiling PHP 8 from source, there are a number of significant configuration flag changes that were first introduced in PHP 7.4 and subsequently carried into PHP 8. The primary change is that we no longer need to specify the directory where libraries are located. PHP 8 now locates libraries using the pkg-config
operating system equivalent.
The following table summarizes compile flag changes. These flags are used with the configure
utility just prior to the actual compile process itself:
Get hands-on with 1400+ tech skills courses.