Webp Image

only webp additions have been made.

This way you can upload images to webp format.

and you can change the format of the thumbnail images that you want.

/app/functions/fn.images.php

function fn_get_supported_image_format_variants()
{
    $formats = array(
        'original' => __('same_as_source'),
    );
$supported_formats = ImageHelper::getSupportedFormats();

if (in_array('jpg', $supported_formats)) {
    $formats['jpg'] = 'JPEG';
}
if (in_array('webp', $supported_formats)) {
    $formats['webp'] = 'WEBP';
}
if (in_array('png', $supported_formats)) {
    $formats['png'] = 'PNG';
}
if (in_array('gif', $supported_formats)) {
    $formats['gif'] = 'GIF';
}

return $formats;

}

function fn_get_image_extension($image_type)
{
    static $image_types = array (
        'image/gif' => 'gif',
        'image/pjpeg' => 'jpg',
        'image/jpeg' => 'jpg',
        'image/webp' => 'webp',
        'image/png' => 'png',
        'application/x-shockwave-flash' => 'swf',
        'image/psd' => 'psd',
        'image/bmp' => 'bmp',
        'image/x-icon' => 'ico',
        'image/vnd.microsoft.icon' => 'ico',
    );

    return isset($image_types[$image_type]) ? $image_types[$image_type] : false;
}
function fn_attach_image_pairs($name, $object_type, $object_id = 0, $lang_code = CART_LANGUAGE, array $object_ids = [])
{
    // @TODO: get rid of direct $_REQUEST array usage inside this function and fn_filter_uploaded_data too
    $allowed_extensions = ['png', 'gif', 'jpg', 'jpeg', 'webp', 'ico'];
    $icons = fn_filter_uploaded_data($name . '_image_icon', $allowed_extensions);
    $detailed = fn_filter_uploaded_data($name . '_image_detailed', $allowed_extensions);
    $pairs_data = !empty($_REQUEST[$name . '_image_data']) ? $_REQUEST[$name . '_image_data'] : [];

    return fn_update_image_pairs($icons, $detailed, $pairs_data, $object_id, $object_type, $object_ids, true, $lang_code);
}
    $filename = 'thumbnails/' . $width . (empty($height) ? '' : '/' . $height) . '/' . $image_path;
    if (Registry::get('settings.Thumbnails.convert_to') != 'original') {
		//delete old display format. Example: image.jpg.webp to image.webp
		$arrFrom = array(".jpg",".png",".gif");
		$filename = str_replace($arrFrom, '', $filename);
	    $filename = $filename . '.' . Registry::get('settings.Thumbnails.convert_to');
    }

......

/app/Tygh/Tools/ImageHelper.php

    public static function getSupportedFormats()
    {
        $imagine = Tygh::$app['image'];
        $supported_formats = array();
    if ($imagine instanceof \Imagine\Imagick\Imagine) {
        $imagick = new \Imagick();

        $supported_formats = array_uintersect(array('jpg', 'webp', 'png', 'gif'), $imagick->queryFormats(), 'strcasecmp');
        $supported_formats = array_map('strtolower', $supported_formats);
        $imagick->clear();
        $imagick->destroy();
        unset($imagick);
    } elseif ($imagine instanceof \Imagine\Gd\Imagine) {
        $gd_formats = imagetypes();

        if ($gd_formats & IMG_JPEG) {
            $supported_formats[] = 'jpg';
        }
        if ($gd_formats & IMG_WEBP) {
            $supported_formats[] = 'webp';
        }
        if ($gd_formats & IMG_PNG) {
            $supported_formats[] = 'png';
        }

        if ($gd_formats & IMG_GIF) {
            $supported_formats[] = 'gif';
        }
    }

    return $supported_formats;
}

optional (note: Imagick must be installed on the server.)

Your GD version must be up to date Example: GD Version 2.8.0 (Php 7.0.10 Added)

?dispatch=settings.manage&section_id=Thumbnails

WEBP (select)

SAVE

dispatch=storage.clear_thumbnails

dispatch=storage.clear_cache

.htaccess add webp (Don't forget to add it for the cache! ..)

sharing is good. :-)

Webp desteklemeyen browserlar icin cozumun nedir ?

aslına bakarsan webp desteklemeyen browserlarda sitenin de birçok fonksiyonu çalışmıyor. Gördüğüm kadarı çoğu destekliyor artık.

Bak webp ye geçmiş https://unitheme.net/

Mobil tablet browserlar sikintiki, yani bu eklentiler browseri kontrol

ediyor desteklemeyenlere jpeg sunuyor safariye jpeg2000 olusturanida var, neyse sen bilirsin

unitheme demo da aşağıdaki eklenti çalışıyor.

CS-Cart add-on - WebP images conversion (alexbranding.com)

only webp additions have been made.

This way you can upload images to webp format.

and you can change the format of the thumbnail images that you want.

/app/functions/fn.images.php

function fn_get_supported_image_format_variants()
{
    $formats = array(
        'original' => __('same_as_source'),
    );
$supported_formats = ImageHelper::getSupportedFormats();

if (in_array('jpg', $supported_formats)) {
    $formats['jpg'] = 'JPEG';
}
if (in_array('webp', $supported_formats)) {
    $formats['webp'] = 'WEBP';
}
if (in_array('png', $supported_formats)) {
    $formats['png'] = 'PNG';
}
if (in_array('gif', $supported_formats)) {
    $formats['gif'] = 'GIF';
}

return $formats;

}

function fn_get_image_extension($image_type)
{
    static $image_types = array (
        'image/gif' => 'gif',
        'image/pjpeg' => 'jpg',
        'image/jpeg' => 'jpg',
        'image/webp' => 'webp',
        'image/png' => 'png',
        'application/x-shockwave-flash' => 'swf',
        'image/psd' => 'psd',
        'image/bmp' => 'bmp',
        'image/x-icon' => 'ico',
        'image/vnd.microsoft.icon' => 'ico',
    );

    return isset($image_types[$image_type]) ? $image_types[$image_type] : false;
}
function fn_attach_image_pairs($name, $object_type, $object_id = 0, $lang_code = CART_LANGUAGE, array $object_ids = [])
{
    // @TODO: get rid of direct $_REQUEST array usage inside this function and fn_filter_uploaded_data too
    $allowed_extensions = ['png', 'gif', 'jpg', 'jpeg', 'webp', 'ico'];
    $icons = fn_filter_uploaded_data($name . '_image_icon', $allowed_extensions);
    $detailed = fn_filter_uploaded_data($name . '_image_detailed', $allowed_extensions);
    $pairs_data = !empty($_REQUEST[$name . '_image_data']) ? $_REQUEST[$name . '_image_data'] : [];

    return fn_update_image_pairs($icons, $detailed, $pairs_data, $object_id, $object_type, $object_ids, true, $lang_code);
}
    $filename = 'thumbnails/' . $width . (empty($height) ? '' : '/' . $height) . '/' . $image_path;
    if (Registry::get('settings.Thumbnails.convert_to') != 'original') {
		//delete old display format. Example: image.jpg.webp to image.webp
		$arrFrom = array(".jpg",".png",".gif");
		$filename = str_replace($arrFrom, '', $filename);
	    $filename = $filename . '.' . Registry::get('settings.Thumbnails.convert_to');
    }

......

/app/Tygh/Tools/ImageHelper.php

    public static function getSupportedFormats()
    {
        $imagine = Tygh::$app['image'];
        $supported_formats = array();
    if ($imagine instanceof \Imagine\Imagick\Imagine) {
        $imagick = new \Imagick();

        $supported_formats = array_uintersect(array('jpg', 'webp', 'png', 'gif'), $imagick->queryFormats(), 'strcasecmp');
        $supported_formats = array_map('strtolower', $supported_formats);
        $imagick->clear();
        $imagick->destroy();
        unset($imagick);
    } elseif ($imagine instanceof \Imagine\Gd\Imagine) {
        $gd_formats = imagetypes();

        if ($gd_formats & IMG_JPEG) {
            $supported_formats[] = 'jpg';
        }
        if ($gd_formats & IMG_WEBP) {
            $supported_formats[] = 'webp';
        }
        if ($gd_formats & IMG_PNG) {
            $supported_formats[] = 'png';
        }

        if ($gd_formats & IMG_GIF) {
            $supported_formats[] = 'gif';
        }
    }

    return $supported_formats;
}

optional (note: Imagick must be installed on the server.)

Your GD version must be up to date Example: GD Version 2.8.0 (Php 7.0.10 Added)

?dispatch=settings.manage§ion_id=Thumbnails

WEBP (select)

SAVE

dispatch=storage.clear_thumbnails

dispatch=storage.clear_cache

.htaccess add webp (Don't forget to add it for the cache! ..)

sharing is good. :-)

We have S3 bucket for images. On insertion a lambda fires that generates the optimized webp images and jpeg images. This works better since slightly older browsers do not support webp.

my vote is going to cart-power's webp addon.

This is a real old browser no longer needed, even if you reject it as much as you want.

There is one more shortcoming, add that too.

Lazy Load (It creates problems.)

/app/functions/fn.images.php

            if (!empty($cont)) {
		$filename = str_replace('jpg', 'webp', $filename);
                list(, $th_filename) = Storage::instance('images')->put($filename, array(
                    'contents' => $cont,
                    'caching' => true
                ));
            }