Post by rph » Fri Apr 05, 2013 12:59 am

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.

-Ryan


rph
Expert Member

Posts

Joined
Fri Jan 08, 2010 5:05 am
Location - Lincoln, Nebraska

Post by storm-cloud » Fri Apr 05, 2013 8:54 am

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

Active Member

Posts

Joined
Wed Feb 22, 2012 8:07 am

Post by rph » Fri Apr 05, 2013 3:12 pm

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>';
}

-Ryan


rph
Expert Member

Posts

Joined
Fri Jan 08, 2010 5:05 am
Location - Lincoln, Nebraska

Post by tkal » Mon Apr 22, 2013 6:42 pm

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

Newbie

Posts

Joined
Sat Apr 13, 2013 9:23 pm

Post by tora0515 » Mon May 27, 2013 3:13 pm

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?

Active Member

Posts

Joined
Fri Jun 15, 2012 3:05 pm

Post by tora0515 » Tue May 28, 2013 11:38 am

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 :)

Attachments


Active Member

Posts

Joined
Fri Jun 15, 2012 3:05 pm

Post by Von Grootel » Mon Jun 03, 2013 8:32 pm

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!

Newbie

Posts

Joined
Sat Apr 07, 2012 5:58 am

Post by MaryMary » Sat Jun 08, 2013 3:56 am

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 ?

Newbie

Posts

Joined
Sat Jun 08, 2013 3:50 am

Post by greenspaceyoga » Thu Jun 13, 2013 8:28 pm

Thanks so much Quforia , works great for me on modified theme 1.5.4.1


Posts

Joined
Tue Apr 30, 2013 4:23 pm

Post by Dunald » Thu Jun 27, 2013 5:52 pm

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

Active Member

Posts

Joined
Tue Mar 15, 2011 9:05 pm

Post by asiegbucp » Tue Jul 23, 2013 11:14 am

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?

Attachments


Newbie

Posts

Joined
Sat Feb 23, 2013 1:34 am

Post by dodokids » Fri Aug 30, 2013 7:59 pm

"The following image(s) are missing width and/or height attributes.
...../image/flags/bg.png (Dimensions: 16 x 11)
... the other languages"

Please help.

New member

Posts

Joined
Mon Jul 30, 2012 6:50 pm

Post by snoopster » Thu Sep 19, 2013 7:07 pm

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!

New member

Posts

Joined
Mon Nov 28, 2011 7:06 am

Post by scanreg » Thu Oct 10, 2013 9:17 pm

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

Active Member

Posts

Joined
Thu May 06, 2010 12:15 am

Post by QuestSuperElf » Sun Nov 03, 2013 1:44 am

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. :-\

Newbie

Posts

Joined
Mon Feb 04, 2013 11:28 am

Post by byens » Tue Jan 07, 2014 5:38 pm

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?

Selling Kristik - Jasa Foto Aura - Jual Lingerie - supplier baju anak - jasa seo


Active Member

Posts

Joined
Sat Dec 11, 2010 12:29 pm
Location - Surabaya

Post by Qphoria » Wed Jan 08, 2014 12:44 am

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

OpenCart 2.0.x Mod Update Info

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by byens » Wed Jan 08, 2014 11:04 am

Thanks Q it works without error now.

Selling Kristik - Jasa Foto Aura - Jual Lingerie - supplier baju anak - jasa seo


Active Member

Posts

Joined
Sat Dec 11, 2010 12:29 pm
Location - Surabaya

Post by Canou » Thu Jan 23, 2014 6:36 pm

IHi Qphoria.

I've this :

Image

Adoucisseur d'eau


Newbie

Posts

Joined
Thu Mar 07, 2013 2:15 am
Location - France

Post by webcentury » Thu Jan 30, 2014 12:42 am

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

We support Students Today
Image
Extensions by WebCentury


New member

Posts

Joined
Mon Oct 14, 2013 3:18 am
Who is online

Users browsing this forum: No registered users and 9 guests