wp_get_webp_info example



    if ( false !== $info ) {
        return $info;
    }

    /* * For PHP versions that don't support WebP images, * extract the image size info from the file headers. */
    if ( 'image/webp' === wp_get_image_mime( $filename ) ) {
        $webp_info = wp_get_webp_info( $filename );
        $width     = $webp_info['width'];
        $height    = $webp_info['height'];

        // Mimic the native return format.         if ( $width && $height ) {
            return array(
                $width,
                $height,
                IMAGETYPE_WEBP,
                sprintf(
                    'width="%d" height="%d"',
                    
 else {
            $quality = $this->get_quality();
        }

        try {
            switch ( $this->mime_type ) {
                case 'image/jpeg':
                    $this->image->setImageCompressionQuality( $quality );
                    $this->image->setImageCompression( imagick::COMPRESSION_JPEG );
                    break;
                case 'image/webp':
                    $webp_info = wp_get_webp_info( $this->file );

                    if ( 'lossless' === $webp_info['type'] ) {
                        // Use WebP lossless settings.                         $this->image->setImageCompressionQuality( 100 );
                        $this->image->setOption( 'webp:lossless', 'true' );
                    } else {
                        $this->image->setImageCompressionQuality( $quality );
                    }
                    break;
                default:
                    $this->image->setImageCompressionQuality( $quality );
            }
Home | Imprint | This part of the site doesn't use cookies.