The gd_edit_image_support() WordPress PHP function checks if the installed version of GD (Graphics Draw) supports a particular image type.
Usage
To use the gd_edit_image_support() function, pass the required mime type (e.g., “image/jpeg”) as a string. This function will return true
if the GD library supports the image type, and false
if it doesn’t.
$mime_type = "image/jpeg"; $supports = gd_edit_image_support($mime_type);
Parameters
- $mime_type (string) – The mime type of the image that you want to check GD support for. For example, “image/jpeg”, “image/png”, “image/gif”, etc.
More information
See WordPress Developer Resources: gd_edit_image_support()
The function is available since WordPress version 3.5.0. It is not deprecated as of the latest WordPress version. You can find its source code in wp-includes/media.php
.
Examples
Checking Support for JPEG Images
This code checks if GD supports editing JPEG images.
$mime_type = "image/jpeg"; if (gd_edit_image_support($mime_type)) { echo "GD supports JPEG images"; } else { echo "GD does not support JPEG images"; }
Checking Support for PNG Images
This code checks if GD supports editing PNG images.
$mime_type = "image/png"; if (gd_edit_image_support($mime_type)) { echo "GD supports PNG images"; } else { echo "GD does not support PNG images"; }
Checking Support for GIF Images
This code checks if GD supports editing GIF images.
$mime_type = "image/gif"; if (gd_edit_image_support($mime_type)) { echo "GD supports GIF images"; } else { echo "GD does not support GIF images"; }
Checking Support for BMP Images
This code checks if GD supports editing BMP images.
$mime_type = "image/bmp"; if (gd_edit_image_support($mime_type)) { echo "GD supports BMP images"; } else { echo "GD does not support BMP images"; }
Checking Support for WEBP Images
This code checks if GD supports editing WEBP images.
$mime_type = "image/webp"; if (gd_edit_image_support($mime_type)) { echo "GD supports WEBP images"; } else { echo "GD does not support WEBP images"; }