Function and usage of gd_edit_image_support() in wordpress


Answers ( 1 )


    The gd_edit_image_support() function in WordPress is a utility function used to check if the installed version of GD (Graphics Draw), a PHP library for image processing, supports a particular image type based on its MIME type.

    Function Prototype:

    gd_edit_image_support( string $mime_type ): bool


    • Purpose: This function is primarily used to determine whether the server's current GD library installation can handle specific image formats. This is crucial for WordPress themes or plugins that deal with image manipulation, as it ensures compatibility and prevents errors when processing images.
    • GD Library: GD is a widely-used library in PHP for image creation and manipulation. It can handle various image formats like JPEG, PNG, and GIF.


    • $mime_type (string, required): The MIME type of the image. MIME types are standardized identifiers used to specify the format of a file. In the context of images, common MIME types include image/jpeg, image/png, image/gif, etc.

    Return Value:

    • bool: The function returns a boolean value.
      • true if the GD library supports the specified MIME type.
      • false if it does not support the specified MIME type or if GD is not available.

    Sample Usage:

    // Check if GD supports JPEG images
    if ( gd_edit_image_support( 'image/jpeg' ) ) {
        echo "GD supports JPEG images.";
    } else {
        echo "GD does not support JPEG images.";
    // Check for PNG support
    if ( gd_edit_image_support( 'image/png' ) ) {
        echo "GD supports PNG images.";
    } else {
        echo "GD does not support PNG images.";

    Additional Notes:

    • Related Function: As mentioned in the description, wp_image_editor_supports() is a related function. It checks for image editing support across all WordPress image editors, not just GD. This can be useful for broader compatibility checks.
    • Server Configuration: The support for different image types can vary based on the server's PHP and GD library configurations. Therefore, it's good practice to use this function before performing image operations that depend on specific image types.

    This function is part of WordPress's efforts to provide robust image handling capabilities, ensuring that themes and plugins can work seamlessly with various image types across different server environments.

Leave an answer