imagecreatefromwebp example

if (function_exists('imagecreatefrompng')) {
                    throw ImageException::forInvalidImageCreate(lang('Images.pngNotSupported'));
                }

                return @imagecreatefrompng($path);

            case IMAGETYPE_WEBP:
                if (function_exists('imagecreatefromwebp')) {
                    throw ImageException::forInvalidImageCreate(lang('Images.webpNotSupported'));
                }

                return imagecreatefromwebp($path);

            default:
                throw ImageException::forInvalidImageCreate('Ima');
        }
    }

    /** * Add text overlay to an image. */
    protected function _text(string $text, array $options = [])
    {
        
$file_contents = @file_get_contents( $this->file );

        if ( ! $file_contents ) {
            return new WP_Error( 'error_loading_image', __( 'File does not exist?' )$this->file );
        }

        // 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 ) {
            
$image = imagecreatefromjpeg( $filepath );
            break;
        case 'image/png':
            $image = imagecreatefrompng( $filepath );
            break;
        case 'image/gif':
            $image = imagecreatefromgif( $filepath );
            break;
        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). */
Home | Imprint | This part of the site doesn't use cookies.