Many thanks!
Many thanks!
UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk
OC version. You'd need to modify your catalog/controller/tool/image.php and admin/controller/tool/image.php file where this line:evopixel wrote: ↑Tue Mar 29, 2022 5:50 pmIs there are a way to change the size of newly uploaded images let's say from 500x500 to 100x100px?
If I do it via System>Settings>Image, OpenCart will update all the current uploaded images, which will affect all the Google ranked images and the quality of the images.
I have uploaded one via FTP and then assigned it to a product, but the image is resized to the default values as set up in (System>Settings>Image).
Many thanks!
Code: Select all
$image->resize($width, $height);
Code: Select all
if ($this->config->get('config_new_image_width') && $this->config->get('config_new_image_height')) {
$image->resize($this->config->get('config_new_image_width'), $this->config->get('config_new_image_height'));
} else {
$image->resize($width, $height);
|
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
So basically create an OCMOD (I am running an OC2.2) with a Find this and Replace for the above script.straightlight wrote: ↑Tue Mar 29, 2022 9:05 pmOC version. You'd need to modify your catalog/controller/tool/image.php and admin/controller/tool/image.php file where this line:evopixel wrote: ↑Tue Mar 29, 2022 5:50 pmIs there are a way to change the size of newly uploaded images let's say from 500x500 to 100x100px?
If I do it via System>Settings>Image, OpenCart will update all the current uploaded images, which will affect all the Google ranked images and the quality of the images.
I have uploaded one via FTP and then assigned it to a product, but the image is resized to the default values as set up in (System>Settings>Image).
Many thanks!
could become:Code: Select all
$image->resize($width, $height);
Notice the: _new_ array key name in the validation for the width and height. You could then add these keys to your OC admin settings page or as a profile into your system/config folder with the use of Event Triggers. However, the tool/image code portion may need to be added as OCMod or VQMod unless creating a controller relationship.Code: Select all
if ($this->config->get('config_new_image_width') && $this->config->get('config_new_image_height')) { $image->resize($this->config->get('config_new_image_width'), $this->config->get('config_new_image_height')); } else { $image->resize($width, $height); |
I will run this on a local server i.e AMPPS and post a reply as soon as I manage to test this out.
Maybe this explanation will help other users that are in the same boat as me ;o)
For example:
Currently, I have: /image/cache/catalog/some-directory/image-name-500x500.jpg, if I update the image size in the Opencart Settings all of my existing images will CHANGE TO /image/cache/catalog/some-directory/image-name-1000x1000.jpg.
Ideally, I would like to keep the old ones as they are and the new ones at a large size (as some of the old will come out as poor quality due to their existing size).
Thank U for assistance straightlight!
Better to validate the entire product itself from the database, since store owners also needs to take under consideration that recurring periods are also involved when indicating that a product is new and that also includes the fact that uploaded images can also be done as a stand-alone product; without the need to be associated with a category.evopixel wrote: ↑Wed Mar 30, 2022 11:35 pmSo basically create an OCMOD (I am running an OC2.2) with a Find this and Replace for the above script.straightlight wrote: ↑Tue Mar 29, 2022 9:05 pmOC version. You'd need to modify your catalog/controller/tool/image.php and admin/controller/tool/image.php file where this line:evopixel wrote: ↑Tue Mar 29, 2022 5:50 pmIs there are a way to change the size of newly uploaded images let's say from 500x500 to 100x100px?
If I do it via System>Settings>Image, OpenCart will update all the current uploaded images, which will affect all the Google ranked images and the quality of the images.
I have uploaded one via FTP and then assigned it to a product, but the image is resized to the default values as set up in (System>Settings>Image).
Many thanks!
could become:Code: Select all
$image->resize($width, $height);
Notice the: _new_ array key name in the validation for the width and height. You could then add these keys to your OC admin settings page or as a profile into your system/config folder with the use of Event Triggers. However, the tool/image code portion may need to be added as OCMod or VQMod unless creating a controller relationship.Code: Select all
if ($this->config->get('config_new_image_width') && $this->config->get('config_new_image_height')) { $image->resize($this->config->get('config_new_image_width'), $this->config->get('config_new_image_height')); } else { $image->resize($width, $height); |
I will run this on a local server i.e AMPPS and post a reply as soon as I manage to test this out.
Maybe this explanation will help other users that are in the same boat as me ;o)
For example:
Currently, I have: /image/cache/catalog/some-directory/image-name-500x500.jpg, if I update the image size in the Opencart Settings all of my existing images will CHANGE TO /image/cache/catalog/some-directory/image-name-1000x1000.jpg.
Ideally, I would like to keep the old ones as they are and the new ones at a large size (as some of the old will come out as poor quality due to their existing size).
Thank U for assistance straightlight!
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
evopixel wrote: ↑Wed Mar 30, 2022 11:35 pm
Maybe this explanation will help other users that are in the same boat as me ;o)
For example:
Currently, I have: /image/cache/catalog/some-directory/image-name-500x500.jpg, if I update the image size in the Opencart Settings all of my existing images will CHANGE TO /image/cache/catalog/some-directory/image-name-1000x1000.jpg.
Ideally, I would like to keep the old ones as they are and the new ones at a large size (as some of the old will come out as poor quality due to their existing size).
Code: Select all
$this->model_tool_image->resize($product_info['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_thumb_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_thumb_height'));
You would most likely need to have logic built in to determine what a “NEW image" VS “OLD image" is: (ex: a flag, timestamp, date added, etc.).
Seems a bit hacky IMO, better off just updating your older images with newer high quality images or try to upscale the older images through an external program and see if you can salvage quality.
-
Full Stack Web Developer :: Send a PM for Custom Work.
Backup and learn how to recover before you make any changes!
Updating the size of the existing images will change the image URL which will result in broken images in Google and across all other marketing channels (Pinterest etc).
I was aiming for a way so that the new image uploads will be at a new resolution/size and the existing images stay the same; this way my current image rankings
will be intact and the new ones are getting an upgrade

If it was a handful that would be fine, but it's in excess of 10000 images...
Thank you's!
At this point, better to create a new service request in the Commercial Support section of the forum to get this done as a custom job.evopixel wrote: ↑Thu Mar 31, 2022 8:40 pmBesides the image quality problem (if I were to upload better images) there is the SEO aspect.
Updating the size of the existing images will change the image URL which will result in broken images in Google and across all other marketing channels (Pinterest etc).
I was aiming for a way so that the new image uploads will be at a new resolution/size and the existing images stay the same; this way my current image rankings
will be intact and the new ones are getting an upgrade![]()
If it was a handful that would be fine, but it's in excess of 10000 images...
Thank you's!
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
It's the same perspective as the above.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
#################################################straightlight wrote: ↑Thu Mar 31, 2022 12:17 amBetter to validate the entire product itself from the database, since store owners also needs to take under consideration that recurring periods are also involved when indicating that a product is new and that also includes the fact that uploaded images can also be done as a stand-alone product; without the need to be associated with a category.evopixel wrote: ↑Wed Mar 30, 2022 11:35 pmSo basically create an OCMOD (I am running an OC2.2) with a Find this and Replace for the above script.straightlight wrote: ↑Tue Mar 29, 2022 9:05 pm
OC version. You'd need to modify your catalog/controller/tool/image.php and admin/controller/tool/image.php file where this line:
could become:Code: Select all
$image->resize($width, $height);
Notice the: _new_ array key name in the validation for the width and height. You could then add these keys to your OC admin settings page or as a profile into your system/config folder with the use of Event Triggers. However, the tool/image code portion may need to be added as OCMod or VQMod unless creating a controller relationship.Code: Select all
if ($this->config->get('config_new_image_width') && $this->config->get('config_new_image_height')) { $image->resize($this->config->get('config_new_image_width'), $this->config->get('config_new_image_height')); } else { $image->resize($width, $height); |
I will run this on a local server i.e AMPPS and post a reply as soon as I manage to test this out.
Maybe this explanation will help other users that are in the same boat as me ;o)
For example:
Currently, I have: /image/cache/catalog/some-directory/image-name-500x500.jpg, if I update the image size in the Opencart Settings all of my existing images will CHANGE TO /image/cache/catalog/some-directory/image-name-1000x1000.jpg.
Ideally, I would like to keep the old ones as they are and the new ones at a large size (as some of the old will come out as poor quality due to their existing size).
Thank U for assistance straightlight!
Tried the code but the website becomes unresponsive....
My code is in: /public_html/catalog/model/tool/image.php
And it looks like this:
Code: Select all
<?php
class ModelToolImage extends Model {
public function resize($filename, $width, $height) {
if (!is_file(DIR_IMAGE . $filename)) {
return;
}
$extension = pathinfo($filename, PATHINFO_EXTENSION);
$old_image = $filename;
$new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
if (!is_file(DIR_IMAGE . $new_image) || (filectime(DIR_IMAGE . $old_image) > filectime(DIR_IMAGE . $new_image))) {
$path = '';
$directories = explode('/', dirname(str_replace('../', '', $new_image)));
foreach ($directories as $directory) {
$path = $path . '/' . $directory;
if (!is_dir(DIR_IMAGE . $path)) {
@mkdir(DIR_IMAGE . $path, 0777);
}
}
list($width_orig, $height_orig) = getimagesize(DIR_IMAGE . $old_image);
if ($width_orig != $width || $height_orig != $height) {
$image = new Image(DIR_IMAGE . $old_image);
$image->resize($width, $height);
$image->save(DIR_IMAGE . $new_image);
} else {
copy(DIR_IMAGE . $old_image, DIR_IMAGE . $new_image);
}
}
if ($this->request->server['HTTPS']) {
return $this->config->get('config_ssl') . 'image/' . $new_image;
} else {
return $this->config->get('config_url') . 'image/' . $new_image;
}
}
}

Users browsing this forum: Majestic-12 [Bot] and 44 guests