Page 2 of 4

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

Posted: Fri Apr 05, 2013 12:59 am
by rph
storm-cloud wrote:Ryan, could you clarify why this method would be considered sloppy code? Is it bad practice to call these attributes within a model/tool file?
The proper method would be for the controller to pass the width and height measurements then have the template put it all together similar to how alt and title tags work. Something like:

Code: Select all

<img src="<?php echo $thumb; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>" alt="<?php echo $heading_title; ?>" />
The cheater method I use appends the extra info to the end of the image path ($thumb in the example above) so:

Code: Select all

http://store.com/image/cache/data/image-60x60.jpg
Get's changed to:

Code: Select all

http://store.com/image/cache/data/image-60x60.jpg" width="60" height="60
The potential problem is if there's an error in the template and the closing double-quote is missing or there's some non-template area of the cart using the ModelToolImage class (such as a custom feed). Also any non-resized images like logo won't have the tags added.

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

Posted: Fri Apr 05, 2013 8:54 am
by storm-cloud
rph wrote:The potential problem is if there's an error in the template and the closing double-quote is missing or there's some non-template area of the cart using the ModelToolImage class (such as a custom feed). Also any non-resized images like logo won't have the tags added.
Yes, I can see this now. These attributes have also been added to our Google Base Feed (standard module included in core) so I would assume that this may cause issues. That's a shame as I am really hoping for a (correct) fix for this.

As mentioned previously, Q's fix seems to produce errors. Any other suggestions? :D

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

Posted: Fri Apr 05, 2013 3:12 pm
by rph
Not sure how you've implemented it but here's the code I use:

Code: Select all

if ($product['image'] && file_exists(DIR_IMAGE . $product['image'])) {
    $output .= '<g:image_link>' . str_replace('" width="500" height="500', '', $this->model_tool_image->resize($product['image'], 500, 500)) . '</g:image_link>';
} else {
    $output .= '<g:image_link>' . str_replace('" width="500" height="500', '', $this->model_tool_image->resize('no_image.jpg', 500, 500)) . '</g:image_link>';
}

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

Posted: Mon Apr 22, 2013 6:42 pm
by tkal
First off, thanks for your contributions on this matter :)

I tried Qphoria's solution which seems to work perfectly but breaks the remove button from the product, as said by others as well.

Then I tried rph's vqmod script, which worked but broke various lightbox and other image scripts I use.

If anyone has a solution for either problem I would be very grateful :)

P.S. Using Opencart 1.5.5.1

Edit: Hacked Qphoria's modification to get around the problem, it's totally hacky but works (don't think it adds too much load, it's an extra if and a strpos for each image the page has).

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]);
           }
It just skips all image tags that have close.png inside them, thus skipping the x button of the cart which was getting broken

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

Posted: Mon May 27, 2013 3:13 pm
by tora0515
rph wrote: The proper method would be for the controller to pass the width and height measurements then have the template put it all together similar to how alt and title tags work. Something like:

Code: Select all

<img src="<?php echo $thumb; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>" alt="<?php echo $heading_title; ?>" />
using 1.5.5.1

I am making a vqmod for the bestseller module to get the image dimensions.

To get this to work:

Code: Select all

<img src="<?php echo $product['thumb']; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>" alt="<?php echo $product['name']; ?>" />
I have add this to the controller:

Code: Select all

<file name="/catalog/controller/module/bestseller.php">	
	<operation>
      <search position="after"><![CDATA[
	  $image = $this->model_tool_image->resize($result['image'], $setting['image_width'], $setting['image_height']);
      ]]></search>
      <add><![CDATA[
	   $this->data['width'] = $setting['image_width'];
	   $this->data['height'] = $setting['image_height'];
	  ]]></add>
    </operation>
	</file>
It hasn't produced any errors, but since I only started on php after getting opencart, I am not confident that this is correct. Any ideas?

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

Posted: Tue May 28, 2013 11:38 am
by tora0515
Here is what I've done so far. Got lazy at the end... just started adding in the width and height on the tpl, controllers are a bit over my head sometimes, so make sure you go over the xml and change the width and height on line 101, 112, 125, 134, and 143. not everything is covered either, I just did the slideshow, bestseller, latest, featured, header logo(line 101), category page(line112), and product page(line 125,134, 143).

Not sure if it works on other installations (mine is 1.5.5.1) or with non-opencart themes, don't know if it works with other mods or xml files. I just made it for my site. So give it a look over and if it works, glad I could help :)

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

Posted: Mon Jun 03, 2013 8:32 pm
by Von Grootel
It doesnt really work for me. Could someone help me out with this matter?

I used the VQMODs in this topic, but i get all kinds of errors. Like a dropdown box that doesnt work. Is there a good solution for this?

Please let me know, many thanks in advance!

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

Posted: Sat Jun 08, 2013 3:56 am
by MaryMary
Is there any fix for this problem, all my products in my opencart sites in my google merchant acct are suspended cause of this problem, is there any def fix out there that works without breaking other modules and giving errors,any vqmods that work for this ?

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

Posted: Thu Jun 13, 2013 8:28 pm
by greenspaceyoga
Thanks so much Quforia , works great for me on modified theme 1.5.4.1

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

Posted: Thu Jun 27, 2013 5:52 pm
by Dunald
Hello everybody!!!

I have been looking like crazy to find why I have strange *');" /> in the cart and a broken X.
Glad to have found the problem at last....

What is the status on this matter?
Is there a solution for the image tags that does not generate any errors?

Please let me know!

Thanks!
/ Dunald

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

Posted: Tue Jul 23, 2013 11:14 am
by asiegbucp
Please I need assistance with image height/width tag and image_width_height_tags.xml
I installed it on my store http://www.buyomart.com but it distorted product images.
Please take a look on the attached screenshot.
Gtmetrix confirmed that the module added image dimensions but the only problem is that it distorted image sizes as shown on the attached screenshot. Please can you help me modify the xml file to work well with my store?

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

Posted: Fri Aug 30, 2013 7:59 pm
by dodokids
"The following image(s) are missing width and/or height attributes.
...../image/flags/bg.png (Dimensions: 16 x 11)
... the other languages"

Please help.

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

Posted: Thu Sep 19, 2013 7:07 pm
by snoopster
Has this error been fixed?

PHP Notice: Undefined offset: 0 in /xxxxxx/vqmod/vqcache/vq2-system_library_response.php on line 119

Other than that, this mod is great! Thank you Qphoria!

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

Posted: Thu Oct 10, 2013 9:17 pm
by scanreg
MaryMary wrote:all my products in my opencart sites in my google merchant acct are suspended cause of this problem
do you mean products submitted using googlefeed?

i looked in their file descrip but i couldn't find where it mentions actual image WxH:

https://support.google.com/merchants/an ... 8494?hl=en
https://support.google.com/merchants/an ... ic=2701481

how did goog indicate that this was the reason for suspending your stuff?

thanks

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

Posted: Sun Nov 03, 2013 1:44 am
by QuestSuperElf
Google Merchant does not like the original VQMOD posted earlier in this thread because it causes invalid image links in the product feed. For example:

Code: Select all

<g:image_link>https://www.EXAMPLE.com/shop/image/cache/data/PRODUCT-500x500.jpg" width="500" height="500>
The result is that Google will disapprove your entire catalog as soon as it sees this. It looks like there may be a fix for this side effect posted above but I have not tried it yet. After having every item in my store disapproved, I'm not ready to try this VQMOD again just yet. :-\

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

Posted: Tue Jan 07, 2014 5:38 pm
by byens
Qphoria wrote:According to Google Page Speed tips. One tip is for web pages to include the width/height tags in the rendered html.
http://code.google.com/speed/page-speed ... Dimensions

So I did some playing with regex on the output code and it seems to be working.
This code will automatically generate the image size tags and insert them into every img tag in your page to comply with the Google Page Speed image tips automatically.

Not sure of the overall performance hit but it works. YMMV:

1. EDIT: system/library/response.php
2. FIND:

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);
	                }
	            }
	        }
	        //
      
with q's mod, i have better result.

However it returns error:
PHP Notice: Undefined offset: 0 in /srv/users/serverpilot/apps/tokolingerie/public/system/library/response.php on line 66

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

php5.5+nginx opencart1.5.4.1

Anyone have solution for this?

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

Posted: Wed Jan 08, 2014 12:44 am
by Qphoria
Try this

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') {

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

Posted: Wed Jan 08, 2014 11:04 am
by byens
Thanks Q it works without error now.

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

Posted: Thu Jan 23, 2014 6:36 pm
by Canou
IHi Qphoria.

I've this :

Image

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

Posted: Thu Jan 30, 2014 12:42 am
by webcentury
There is a module to do this without problems for OC 1.5+ and OC1.6+

Here it is Image width and height tags generator