Page 3 of 4

Re: [MOD] Auto-Include width/height tags for images

Posted: Thu Jan 30, 2014 2:51 am
by Canou
Hi. Thanks, but with this module, i've alway :
Image

Re: [MOD] Auto-Include width/height tags for images

Posted: Wed Feb 19, 2014 3:38 am
by golfmad123
Hi, this post has been really helpful but i have a slight problem. I hope you guys can please help me.

I posted Qphorias code into response.php

Code: Select all

if ($this->level) {
3. BEFORE, ADD:

Code: Select all

//Q: Add width/height tags to all images for Google Page Speed tip:
           //http://code.google.com/speed/page-speed/docs/rendering.html#SpecifyImageDimensions
           preg_match_all('/<img[^>]+>/i', $this->output, $result);

           $img = array();
           foreach($result[0] as $img_tag) {
               preg_match_all('/(width|height|src)=("[^"]*")/i',$img_tag, $img[$img_tag]);
           }

           foreach ($img as $k => $info) {
               if (count($info) == 3 && $info[1][0] == 'src') {
               //if (curl_init(str_replace('"', '', $info[2][0]))) {
               $imgfile = str_replace('"', '', $info[2][0]);
               $imgfile = str_replace(HTTP_SERVER, DIR_IMAGE . '../', $imgfile);
               $imgfile = str_replace(HTTPS_SERVER, DIR_IMAGE . '../', $imgfile);
                   if (file_exists($imgfile)) {
                       $image_info = getImageSize(str_replace('"', '', $imgfile));
                       $k = trim($k, '/>');
                       $k = trim($k, '>');
                       $this->output = str_replace($k, ($k . ' ' . $image_info[3]), $this->output);
                   }
               }
           }
           //


I then got an error message saying
Notice: Undefined offset: 0 in /home/sites/philipsgolf.co.uk/public_html/system/library/response.php on line 66Notice: Undefined offset: 0 in /home/sites/philipsgolf.co.uk/public_html/system/library/response.php on line 66Notice: Undefined offset: 0 in /home/sites/philipsgolf.co.uk/public_html/system/library/response.php on line 66Notice: Undefined offset: 0 in /home/sites/philipsgolf.co.uk/public_html/system/library/response.php on line 66

So I applied the change as suggested by Qphoria
Change

Code: Select all

if (count($info) == 3 && $info[1][0] == 'src') {
to

Code: Select all

if (count($info) == 3 && isset($info[1][0]) && $info[1][0] == 'src') {
This worked but then brought the symbols *');" /> after the X for remove from cart and stopped it from working.
The modification also distorted my homepage logo on a mobile device and distorted the carousel images on a mobile deivice, but they displayed correct in a desktop browser.

I then tried a change as suggested by tkal to remove the *');" /> symbols
From Qphoria's first post change:

Code: Select all

foreach($result[0] as $img_tag) {
         
               preg_match_all('/(width|height|src)=("[^"]*")/i',$img_tag, $img[$img_tag]);
           }


to

Code: Select all

 foreach($result[0] as $img_tag) {
            if (!strpos($img_tag,'close.png'))
               preg_match_all('/(width|height|src)=("[^"]*")/i',$img_tag, $img[$img_tag]);
           }
This did not remove the *');" /> symbols.

So my code is looking like

Code: Select all

<?php
class Response {
	private $headers = array(); 
	private $level = 0;
	private $output;
	
	public function addHeader($header) {
		$this->headers[] = $header;
	}

	public function redirect($url) {
		header('Location: ' . $url);
		exit;
	}
	
	public function setCompression($level) {
		$this->level = $level;
	}
		
	public function setOutput($output) {
		$this->output = $output;
	}

	private function compress($data, $level = 0) {
		if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false)) {
			$encoding = 'gzip';
		} 

		if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== false)) {
			$encoding = 'x-gzip';
		}

		if (!isset($encoding)) {
			return $data;
		}

		if (!extension_loaded('zlib') || ini_get('zlib.output_compression')) {
			return $data;
		}

		if (headers_sent()) {
			return $data;
		}

		if (connection_status()) { 
			return $data;
		}
		
		$this->addHeader('Content-Encoding: ' . $encoding);

		return gzencode($data, (int)$level);
	}

	public function output() {
		if ($this->output) {
			//Q: Add width/height tags to all images for Google Page Speed tip:
           //http://code.google.com/speed/page-speed/docs/rendering.html#SpecifyImageDimensions
           preg_match_all('/<img[^>]+>/i', $this->output, $result);

           $img = array();
           foreach($result[0] as $img_tag) {
               preg_match_all('/(width|height|src)=("[^"]*")/i',$img_tag, $img[$img_tag]);
           }

           foreach ($img as $k => $info) {
           if (count($info) == 3 && isset($info[1][0]) && $info[1][0] == 'src') {
               //if (curl_init(str_replace('"', '', $info[2][0]))) {
               $imgfile = str_replace('"', '', $info[2][0]);
               $imgfile = str_replace(HTTP_SERVER, DIR_IMAGE . '../', $imgfile);
               $imgfile = str_replace(HTTPS_SERVER, DIR_IMAGE . '../', $imgfile);
                   if (file_exists($imgfile)) {
                       $image_info = getImageSize(str_replace('"', '', $imgfile));
                       $k = trim($k, '/>');
                       $k = trim($k, '>');
                       $this->output = str_replace($k, ($k . ' ' . $image_info[3]), $this->output);
                   }
               }
           }
           //
if ($this->level) {
				$ouput = $this->compress($this->output, $this->level);
			} else {
				$ouput = $this->output;
			}	
				
			if (!headers_sent()) {
				foreach ($this->headers as $header) {
					header($header, true);
				}
			}
			
			echo $ouput;
		}
	}
}
?>
Any ideas how to remove the *');" /> error from the checkout??

I would really appreciate some help, this post has been really informative, i am so close just got this tiny error to be fixed. As you can probably tell I am new to code. I hope i have provided all the necessary info. Also I am using version 1.5.5.1.

Thank You

Re: [MOD] Auto-Include width/height tags for images

Posted: Wed May 07, 2014 5:45 am
by yorkfirearms
golfmad123 wrote: Any ideas how to remove the *');" /> error from the checkout??

I would really appreciate some help, this post has been really informative, i am so close just got this tiny error to be fixed. As you can probably tell I am new to code. I hope i have provided all the necessary info. Also I am using version 1.5.5.1.

Thank You
I have the same issue. Any help?

Re: [MOD] Auto-Include width/height tags for images

Posted: Sat Jul 12, 2014 4:12 pm
by mutemancer
Hallo,

I want use your auto width, hegiht tag xml file but I have one problem.

If I use it on my kravat page : www.verdtoneshop.com/kravat

It works well.

But If I use it on my gomlek category: www.verdtoneshop.com/gomlek

There is error. like

Warning: file_get_contents(): Unable to access /home/verdtone/public_html/image/cache/data/Gomlekler/4812-500A-02-200x260.jpg" width="200" height="260 in /home/verdtone/public_html/catalog/model/tool/labelimage.php on line 13Warning: file_get_contents(/home/verdtone/public_html/image/cache/data/Gomlekler/4812-500A-02-200x260.jpg" width="200" height="260): failed to open stream: No such file or directory in /home/verdtone/public_html/catalog/model/tool/labelimage.php on line 13Warning: imagecreatefromstring(): Empty string or invalid image in /home/verdtone/public_html/catalog/model/tool/labelimage.php on line 13Warning: imagesx() expects parameter 1 to be resource, boolean given in /home/verdtone/public_html/catalog/model/tool/labelimage.php on line 38Warning: imagecopy() expects parameter 1 to be resource, boolean given in /home/verdtone/public_html/catalog/model/tool/labelimage.php on line 115Warning: imagesavealpha() expects parameter 1 to be resource, boolean given in /home/verdtone/public_html/catalog/model/tool/labelimage.php on line 39Warning: imagepng() expects parameter 1 to be resource, boolean given in /home/verdtone/public_html/catalog/model/tool/labelimage.php on line 70Warning: file_get_contents(): Unable to access /home/verdtone/public_html/image/cache/data/Gomlekler/9999-500A-04-200x260.jpg" width="200" height="260 in /home/verdtone/public_html/catalog/model/tool/labelimage.php on line 13Warning: file_get_contents(/home/verdtone/public_html/image/cache/data/Gomlekler/9999-500A-04-200x260.jpg" width="200" height="260): failed to open stream: No such file or directory in /home/verdtone/public_html/catalog/model/tool/labelimage.php on line 13Warning: imagecreatefromstring(): Empty string or invalid image in /home/verdtone/public_html/catalog/model/tool/labelimage.php on line 13Warning: imagesx() expects parameter 1 to be resource, boolean given in /home/verdtone/public_html/catalog/model/tool/labelimage.php on line 38Warning: imagecopy() expects parameter 1 to be resource, boolean given in /home/verdtone/public_html/catalog/model/tool/labelimage.php on line 115Warning: imagesavealpha() expects parameter 1 to be resource, boolean given in /home/verdtone/public_html/catalog/model/tool/labelimage.php on line 39Warning: imagepng() expects parameter 1 to be resource, boolean given in /home/verdtone/public_html/catalog/model/tool/labelimage.php on line 70Warning: file_get_contents(): Unable to access /home/verdtone/public_html/image/cache/data/Gomlekler/9999-500A-05-200x260.jpg" width="200" height="260 in /home/verdtone/public_html/catalog/model/tool/labelimage.php on line 13Warning: file_get_contents(/home/verdtone/public_html/image/cache/data/Gomlekler/9999-500A-05-200x260.jpg" width="200" height="260): failed to open stream: No such file or directory in /home/verdtone/public_html/catalog/model/tool/labelimage.php on line 13Warning: imagecreatefromstring(): Empty string or invalid image in /home/verdtone/public_html/catalog/model/tool/labelimage.php on line 13Warning: imagesx() expects parameter 1 to be resource, boolean given in...

How can I fix it ?

Thank you so much !

Re: [MOD] Auto-Include width/height tags for images

Posted: Sat Oct 18, 2014 5:24 am
by Jaap
I Installed the mod.
But this kills my page load time.
Plus 0.8 sec.

Re: [MOD] Auto-Include width/height tags for images

Posted: Sun Oct 19, 2014 11:12 am
by astott2014
I have done the instructions given in post 1, and It has totally messed me images sizes??

Re: [MOD] Auto-Include width/height tags for images

Posted: Tue Oct 21, 2014 9:30 am
by astott2014
Anyone? My images are all stretches higher when using this code, when I remove the code it works fine.

Re: [MOD] Auto-Include width/height tags for images

Posted: Mon Jan 26, 2015 6:36 pm
by ForgetfulGuru
@ Qphoria, You are a STAR. ;D

error“Image width & height dimensions required” in Opencart

Posted: Wed Jan 28, 2015 2:42 am
by sud0074
Hello i am using Opencart v2.0, I want to show my products in Home page as Best seller product, for that i using Best Seller Extension [while i am adding in Best seller modules fields its show error (image width & height dimensions required)

what i did. 1-In bestseller modules when i clicked at plus button to add new modules, 2- Satus is Enable 2- I put it value 5 in Limit box and
3- in Image (W x H) and Resize Type Box i put value W-200 and H-200 (for dimensions) 4- then when i clicked on Save button 5- after that error massage will occur (image width & height dimensions required)]

I try lots of thing but didn't work, i change browser also clear catch but all fail, I also uploaded Screen Shot. please help me out what i am doing wrong.? tell me

Re: [MOD] Auto-Include width/height tags for images

Posted: Thu Jan 29, 2015 2:52 pm
by ForgetfulGuru
With 200px being the defaults for width and height, first thing I'd try is deleting those values and putting something fresh in the boxes.
I would also uninstall the module and reinstall it from the main module's screen.

Re: [MOD] Auto-Include width/height tags for images

Posted: Tue Feb 03, 2015 5:01 pm
by sud0074
@ForgetfulGuru
thanks for giving me feed back but sorry dear .. its also not working
What I did ..
I went in to Module> uninstall Bestseller Module >refresh browser>Install>Clicked Edit>Open Bestseller module>Select enable>add new one >Limit-4,Widht-100,Hight-100( I put fresh Value in all field) >Clicked Save>Error-"Image width & height dimensions required!"

Please tell me where I am wrong and how am I fixed this .

Re: [MOD] Auto-Include width/height tags for images

Posted: Tue Feb 03, 2015 6:54 pm
by ForgetfulGuru
It may be seen as hi-jacking this thread, as it's not really what is being discussed here.

Follow this link to http://forum.opencart.com/viewforum.php?f=190

Ask your question there as it would be a more appropriate place for it.

Re: [MOD] Auto-Include width/height tags for images

Posted: Tue Feb 03, 2015 10:02 pm
by sud0074
@ForgetfulGuru
thnks for this help .. would u like in touch with me .

Re: [MOD] Auto-Include width/height tags for images

Posted: Sun Feb 15, 2015 3:11 am
by BOBKIM7080
For v1.5.6
not works for "qphoria" method.
works "rph" method but my site drop down option menu not works at products page.
Any improvement for this treat?

Re: [MOD] Auto-Include width/height tags for images

Posted: Mon Mar 30, 2015 9:42 pm
by dpinney
Any of these suggestions work with opencart 1.5.6.4 Thanks!

Re: [MOD] Auto-Include width/height tags for images

Posted: Wed Jul 15, 2015 9:30 am
by IP_CAM
This one works for OC Version, up to v.1.5.6.5_rc:
it's called: image_width_height_tags_156.xml

Code: Select all

<?xml version="1.0" encoding="utf-8" ?>
<modification>
<id>Image Width and Height Attributes</id>
<version>1.0.0</version>
<vqmver>2.3.2</vqmver>
<author>OpenCartHelp.com</author>
	<!--
	This isn't an ideal method for adding image width and height attributes
	as it relies on the template to provide the proper closing double-quote (") 
	but it does have the advantage of requiring a minimum of changes versus 
	a proper store wide MVC rewrite.  It will have no effect on non-resized images.  
	There may also be errors where the resize() method is used in non-tempate 
	areas such as a	product feed.
	-->
	<file name="catalog/model/tool/image.php">
		<operation error="log">
			<!--
				1.4.9.x - 1.5.4.1:
					return HTTPS_IMAGE . $new_image;
					return HTTP_IMAGE . $new_image;
				1.5.5.x - 1.5.6.5_rc:
					return $this->config->get('config_ssl') . 'image/' . $new_image;
					return $this->config->get('config_url') . 'image/' . $new_image;
			-->
			<search position="replace" regex="true"><![CDATA[~return (.*) \. \$new_image;~]]></search>
			<add><![CDATA[return $1 . $new_image . '" width="' . $width . '" height="' . $height;]]></add>
		</operation>
	</file>
</modification>
Good Luck ;)
Ernie
hitline.info/shop/

Re: [MOD] Auto-Include width/height tags for images

Posted: Thu Jul 30, 2015 7:30 am
by Axel Wers
IP_CAM wrote:This one works for OC Version, up to v.1.5.6.5_rc:
it's called: image_width_height_tags_156.xml
Thanks, it seems this really works.

Re: [MOD] Auto-Include width/height tags for images

Posted: Thu Jul 30, 2015 8:30 am
by IP_CAM
Your'e welcome!
Ernie

Re: [MOD] Auto-Include width/height tags for images

Posted: Mon Aug 24, 2015 8:36 am
by jaydean
I tried this mod and it only works when I manually edit the response.php file as indicated in this forum. It only adds the image dimensions for the actual category image but not to the products. I use Jays page cache so not sure if this effects it.

Dean

Re: [MOD] Auto-Include width/height tags for images

Posted: Wed Sep 16, 2015 7:50 am
by Axel Wers
IP_CAM wrote:This one works for OC Version, up to v.1.5.6.5_rc:
it's called: image_width_height_tags_156.xml
Hi, this generally works, but since I have installed this, in server error log I have lot of these logs:

Code: Select all

www.domain.tld [Tue Sep 15 06:52:50 2015] [error] [client xx.xx.xx.xx.] File does not exist: /root_path/image/cache/data/folder/title-500x500.jpg"+width="500"+height="500
What is wrong?