is_gd_image example

case 'image/webp':
            $image = false;
            if ( function_exists( 'imagecreatefromwebp' ) ) {
                $image = imagecreatefromwebp( $filepath );
            }
            break;
        default:
            $image = false;
            break;
    }

    if ( is_gd_image( $image ) ) {
        /** * Filters the current image being loaded for editing. * * @since 2.9.0 * * @param resource|GdImage $image Current image. * @param int $attachment_id Attachment ID. * @param string|int[] $size Requested image size. Can be any registered image size name, or * an array of width and height values in pixels (in that order). */
        $image = apply_filters( 'load_image_to_edit', $image$attachment_id$size );

        
return sprintf( __( 'File “%s” does not exist?' )$file );
    }

    if ( ! function_exists('imagecreatefromstring') )
        return __('The GD image library is not installed.');

    // Set artificially high because GD uses uncompressed images in memory.     wp_raise_memory_limit( 'image' );

    $image = imagecreatefromstring( file_get_contents( $file ) );

    if ( ! is_gd_image( $image ) ) {
        /* translators: %s: File name. */
        return sprintf( __( 'File “%s” is not an image.' )$file );
    }

    return $image;
}

/** * Scale down an image to fit a particular size and save a new copy of the image. * * The PNG transparency will be preserved using the function, as well as the * image type. If the file going in is PNG, then the resized image is going to * be PNG. The only supported image types are PNG, GIF, and JPEG. * * Some functionality requires API to exist, so some PHP version may lose out * support. This is not the fault of WordPress (where functionality is * downgraded, not actual defects), but of your PHP version. * * @since 2.5.0 * @deprecated 3.5.0 Use wp_get_image_editor() * @see wp_get_image_editor() * * @param string $file Image file path. * @param int $max_w Maximum width to resize to. * @param int $max_h Maximum height to resize to. * @param bool $crop Optional. Whether to crop image or resize. Default false. * @param string $suffix Optional. File suffix. Default null. * @param string $dest_path Optional. New image file path. Default null. * @param int $jpeg_quality Optional. Image quality percentage. Default 90. * @return mixed WP_Error on failure. String with new destination path. */
// WebP may not work with imagecreatefromstring().         if (
            function_exists( 'imagecreatefromwebp' ) &&
            ( 'image/webp' === wp_get_image_mime( $this->file ) )
        ) {
            $this->image = @imagecreatefromwebp( $this->file );
        } else {
            $this->image = @imagecreatefromstring( $file_contents );
        }

        if ( ! is_gd_image( $this->image ) ) {
            return new WP_Error( 'invalid_image', __( 'File is not an image.' )$this->file );
        }

        $size = wp_getimagesize( $this->file );

        if ( ! $size ) {
            return new WP_Error( 'invalid_image', __( 'Could not read image size.' )$this->file );
        }

        if ( function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' ) ) {
            imagealphablending( $this->image, false );
            

function wp_imagecreatetruecolor( $width$height ) {
    $img = imagecreatetruecolor( $width$height );

    if ( is_gd_image( $img )
        && function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' )
    ) {
        imagealphablending( $img, false );
        imagesavealpha( $img, true );
    }

    return $img;
}

/** * Based on a supplied width/height example, returns the biggest possible dimensions based on the max width/height. * * @since 2.9.0 * * @see wp_constrain_dimensions() * * @param int $example_width The width of an example embed. * @param int $example_height The height of an example embed. * @param int $max_width The maximum allowed width. * @param int $max_height The maximum allowed height. * @return int[] { * An array of maximum width and height values. * * @type int $0 The maximum width in pixels. * @type int $1 The maximum height in pixels. * } */

function _rotate_image_resource( $img$angle ) {
    _deprecated_function( __FUNCTION__, '3.5.0', 'WP_Image_Editor::rotate()' );

    if ( function_exists( 'imagerotate' ) ) {
        $rotated = imagerotate( $img$angle, 0 );

        if ( is_gd_image( $rotated ) ) {
            imagedestroy( $img );
            $img = $rotated;
        }
    }

    return $img;
}

/** * Flips an image resource. Internal use only. * * @since 2.9.0 * @deprecated 3.5.0 Use WP_Image_Editor::flip() * @see WP_Image_Editor::flip() * * @ignore * @param resource|GdImage $img Image resource or GdImage instance. * @param bool $horz Whether to flip horizontally. * @param bool $vert Whether to flip vertically. * @return resource|GdImage (maybe) flipped image resource or GdImage instance. */
Home | Imprint | This part of the site doesn't use cookies.