Page 1 of 1

Adoption of WebP image format

Posted: Wed Apr 08, 2015 11:55 pm
by lz1nud
Any plans for opencart to handle new WebP image format? Or parhaps extention module to be able to convert and read those images. It will be great for speeding up sites.

Re: Adoption of WebP image format

Posted: Thu Apr 09, 2015 6:23 pm
by IP_CAM
What's the Use of it, if no Browsers will display it? It may be a very usable future Option, but at present, it's about as useful as a dead cat.
Ernie

Re: Adoption of WebP image format

Posted: Thu Apr 09, 2015 8:23 pm
by lz1nud
Old browsers can read it with java script, new ones will have the feature to read it. After all this is google development with free open source code. The image can be transparent, so it can replace bigger PNG files too.

Re: Adoption of WebP image format

Posted: Tue Apr 14, 2015 3:30 pm
by fido-x
It doesn't matter whether the browser supports it or not.

Even if you added the extension and mime types to the supported list under the "Server" tab in your store settings in the admin and modified the image library functions, if it is not supported by PHP, then you are just wasting your time.

Re: Adoption of WebP image format

Posted: Sat Jan 05, 2019 5:02 am
by Rainforest
resurrecting this as now in 2019 70+% of browsers can.
Thank you...next.
So any plans for OC to adopt this?

Re: Adoption of WebP image format

Posted: Sun Feb 24, 2019 11:30 pm
by eaglenik
Any info regarding this matter ? Thank you !

Re: Adoption of WebP image format

Posted: Fri Mar 01, 2019 9:56 pm
by letxobnav
not so difficult to add this yourself in the image class.
but keep in mind that you will have to cache both jpg and webp versions of the images as not all browsers accept webp.
and you have to perform the accept check to determine if you return webp or jpg.

Re: Adoption of WebP image format

Posted: Fri Mar 01, 2019 10:03 pm
by letxobnav
and your version of gd has to support it so for every image output you have to perform the check.

Code: Select all

	public function webpSupport() {
		$support = false;
		$gd = gd_info();
		// if gd supports webp
		if ($gd['WebP Support']) {
			// if browser accepts webp images
			if (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'webp')) {
				$support = true;
			}
		}
		return $support;
	}	

Re: Adoption of WebP image format

Posted: Fri Mar 01, 2019 10:11 pm
by straightlight
If the above code needs to be added in an Opencart PHP file, replace this line:

Code: Select all

if (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'webp')) {
with:

Code: Select all

if (isset($this->request->server['HTTP_ACCEPT']) && strpos($this->request->server['HTTP_ACCEPT'], 'webp')) {

Re: Adoption of WebP image format

Posted: Sat Mar 02, 2019 3:17 pm
by letxobnav
true, and if you are sure your php gd version support webp you can take out the gd_info() part of the check.

then you would send out the right images by:

Code: Select all

if ($this->request->server['HTTPS']) {
	return $this->config->get('config_ssl') . 'image/' . ($this->webp_support() ? $your_webp_image : $your_jpg_image);
} else {
	return $this->config->get('config_url') . 'image/' . ($this->webp_support() ? $your_webp_image : $your_jpg_image);
}

Re: Adoption of WebP image format

Posted: Sat Mar 02, 2019 8:44 pm
by straightlight
letxobnav wrote:
Sat Mar 02, 2019 3:17 pm
true, and if you are sure your php gd version support webp you can take out the gd_info() part of the check.

then you would send out the right images by:

Code: Select all

if ($this->request->server['HTTPS']) {
	return $this->config->get('config_ssl') . 'image/' . ($this->webp_support() ? $your_webp_image : $your_jpg_image);
} else {
	return $this->config->get('config_url') . 'image/' . ($this->webp_support() ? $your_webp_image : $your_jpg_image);
}
In accordance to: http://php.net/manual/en/image.constants.php , as for PHP v7.1.0 , there's a similar way to adapt this without validation needed in both admin/model/tool/image.php and catalog/model/tool/image.php files.

Find:

Code: Select all

if (!in_array($image_type, array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF))) { 
replace with:

Code: Select all

if (!in_array($image_type, array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_WEBP))) {
since IMAGETYPE_WEBP, in this case, is already verified with the image size. When that fails, the old image file will be loaded on anyhow.

Note: Not a replacement solution, simply an addition to it.

Re: Adoption of WebP image format

Posted: Wed Jun 05, 2019 11:05 am
by arcovirtual
I have a mod from a developer, which generates a constant error every certain hour of the day, and it has to do with the same thing that you are talking about in this thread,
the code with problems is this,

Code: Select all

	public function webpSupport() {
				$mod = 'rm_lwi';
				$support = false;
				if ($this->config->get($mod . '_status') && $this->config->get($mod . '_webp_status')) {
					$gd = gd_info();
					if ($gd['WebP Support'] && strpos( $_SERVER['HTTP_ACCEPT'], 'webp' ) ) { //this line error HTTP_ACCEPT unable or empty
						$support = true;
					}
				}
				return $support;
			}
I am trying to do this with what I have read from you:

Code: Select all

	if ($gd['WebP Support'] && (strpos( $_SERVER['HTTP_ACCEPT'], 'image/webp' ) !== false )) {
I have to wait until tomorrow to check if this solves that error

Re: Adoption of WebP image format

Posted: Wed Jun 05, 2019 11:21 am
by arcovirtual
ok the error follow:
PHP Notice: Undefined index: HTTP_ACCEPT in /home/........./public_html/system/storage/modification/catalog/model/tool/image.php on line 8

Code: Select all

if ($gd['WebP Support'] && (strpos( $_SERVER['HTTP_ACCEPT'], 'image/webp' ) !== false )) {
I do not know how to solve it

Re: Adoption of WebP image format

Posted: Wed Jun 05, 2019 11:27 am
by arcovirtual
I will try with this:

Code: Select all

public function webpSupport() {
				$mod = 'rm_lwi';
				$support = false;
				if ($this->config->get($mod . '_status') && $this->config->get($mod . '_webp_status')) {
					$gd = gd_info();
					if ($gd['WebP Support'])
					{
			// if browser accepts webp images
			if (isset($this->request->server['HTTP_ACCEPT']) && strpos($this->request->server['HTTP_ACCEPT'], 'webp')) {
			
						$support = true;
					}
				}
				return $support;
			}
			}
			

Re: Adoption of WebP image format

Posted: Wed Jun 05, 2019 11:41 am
by IP_CAM
did you really define this http-accept command/whatever /variable ?
if it's not defined, it can not be understud and handled accordingly, since it's
not an OC default global variable, as I am aware of.
Ernie
https://stackoverflow.com/questions/513 ... ttp-accept

Re: Adoption of WebP image format

Posted: Wed Jun 05, 2019 7:19 pm
by straightlight
See this topic for WebP support: viewtopic.php?f=121&t=210243&p=748237#p747798

As for the HTTP_ACCEPT, see this post for more info: https://stackoverflow.com/questions/502 ... ttp-accept .

Re: Adoption of WebP image format

Posted: Wed Jun 05, 2019 8:25 pm
by dparakhiya

Re: Adoption of WebP image format

Posted: Wed Jul 17, 2019 10:09 am
by straightlight
dparakhiya wrote:
Wed Jun 05, 2019 8:25 pm
Maybe this Module useful: https://www.opencart.com/index.php?rout ... n_id=36923
I am not sure how useful it could become since it has a 404 error message on the page.

Re: Adoption of WebP image format

Posted: Wed Nov 27, 2019 12:05 am
by agatha65

Re: Adoption of WebP image format

Posted: Sun Feb 13, 2022 8:36 am
by by mona
For a more complete solution, developed to include all images not just product thumbs.

https://www.opencart.com/index.php?rout ... n_id=43173