Page 4 of 4
Re: [MOD] Auto-Include width/height tags for images
Posted: Wed Sep 16, 2015 10:08 am
by IP_CAM
I have put together a few sample files, a while ago:
http://www.opencart.com/index.php?route ... n_id=23506
Further: In order to have ALL images 'DONE', it takes a little work, to find, troughout the
ALL_FILENAMES.TPL Source-Files, all image Links, and manually hardcode the width+height, where real VALUES are missing on Browser Page Source. In Addition, in some VqMod's may be some image Links as well, they have to be renamed too, if one wants to make it complete.
Ernie
bigmax.ch/shop/
Re: [MOD] Auto-Include width/height tags for images
Posted: Sun Mar 06, 2016 8:31 am
by saliverdim
ı Looking oc mod or vqmod oc 2.0.3.1
1-Specify image dimensions opencart
2-Serve scaled images opencart
can you help me ?
Re: [MOD] Auto-Include width/height tags for images
Posted: Tue Sep 06, 2016 10:50 pm
by esponi
Have you found it?
Re: [MOD] Auto-Include width/height tags for images
Posted: Sat Oct 29, 2016 7:55 am
by IP_CAM
saliverdim wrote:ı Looking oc mod or vqmod oc 2.0.3.1
1-Specify image dimensions opencart
2-Serve scaled images opencart
can you help me ?
As I recall, such Mod exists already for some OC-2.
But I cannot longer create&test such Mod's, because I have no working V-2 Versions online.
Ernie
Re: [MOD] Auto-Include width/height tags for images
Posted: Mon Oct 02, 2017 6:14 pm
by guidone
Hi,
for OC 2 i'm using this vQmod, is any problem with this?
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<modification>
<id>Images width and height tags</id>
<version>1.0.0</version>
<vqmver required="true">2.4.0</vqmver>
<author>me</author>
<file name="catalog/model/tool/image.php">
<operation>
<search position="replace"><![CDATA[$image_new;]]></search>
<add><![CDATA[$image_new . '" width="' . $width . '" height="' . $height;]]></add>
</operation>
</file>
</modification>
Re: [MOD] Auto-Include width/height tags for images
Posted: Tue Oct 03, 2017 4:01 am
by IP_CAM
I explained it here, and added a VqMod as well as an OcMod to it:
viewtopic.php?f=190&t=185410&p=686890#p686890
Good Luck!
Ernie
Re: [MOD] Auto-Include width/height tags for images
Posted: Mon Oct 09, 2017 12:57 pm
by tonkp
It works! Thank You
sbobet
Re: [MOD] Auto-Include width/height tags for images
Posted: Tue May 11, 2021 2:22 am
by guidone
This code it works great but on main domain only, not multistore, any solution?
Thanks
byens wrote: ↑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:
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: Sun Sep 12, 2021 9:12 pm
by DoctorDredd
Qphoria wrote: ↑Wed Sep 15, 2010 11:18 pm
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, '>');
[b]$this->output = str_replace($k, ($k . ' ' . $image_info[3]), $this->output);[/b]
}
}
}
//
This is wonderful code. To much speed up site. But come some small foult:
Notice: Trying to access array offset on value of type bool in /vqmod/vqcache/vq2-system_library_response.php on line 168
$this->output = str_replace($k, ($k . ' ' . $image_info[3]), $this->output);
And also strached images. Opencart 1.5.6.5 Please help to repair. Thanks in advance.!