Post by evopixel » Tue Mar 29, 2022 5:50 pm

Is 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!

      New member

      Posts

      Joined
      Mon Apr 28, 2014 4:20 pm

      Post by paulfeakins » Tue Mar 29, 2022 7:54 pm

      So you want to change the size of images but you don't want to change the size of images?

      UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


      User avatar
      Legendary Member
      Online

      Posts

      Joined
      Mon Aug 22, 2011 11:01 pm
      Location - London Gatwick, United Kingdom

      Post by straightlight » Tue Mar 29, 2022 9:05 pm

      evopixel wrote:
      Tue Mar 29, 2022 5:50 pm
      Is 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!
          OC version. You'd need to modify your catalog/controller/tool/image.php and admin/controller/tool/image.php file where this line:

          Code: Select all

          $image->resize($width, $height);
          
          could become:

          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);
          |
          
          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.

          Dedication and passion goes to those who are able to push and merge a project.

          Regards,
          Straightlight
          Programmer / Opencart Tester


          Legendary Member

          Posts

          Joined
          Mon Nov 14, 2011 11:38 pm
          Location - Canada, ON

          Post by straightlight » Wed Mar 30, 2022 5:09 am

          This extension may help: https://www.opencart.com/index.php?rout ... n_id=27764 . You can also contact the extension developer to have this extension developed for OC v3.x releases or create a new service request in the Commercial Support section of the forum to have it done as a custom job.

          Dedication and passion goes to those who are able to push and merge a project.

          Regards,
          Straightlight
          Programmer / Opencart Tester


          Legendary Member

          Posts

          Joined
          Mon Nov 14, 2011 11:38 pm
          Location - Canada, ON

          Post by evopixel » Wed Mar 30, 2022 11:35 pm

          straightlight wrote:
          Tue Mar 29, 2022 9:05 pm
          evopixel wrote:
          Tue Mar 29, 2022 5:50 pm
          Is 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!
              OC version. You'd need to modify your catalog/controller/tool/image.php and admin/controller/tool/image.php file where this line:

              Code: Select all

              $image->resize($width, $height);
              
              could become:

              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);
              |
              
              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.
              So basically create an OCMOD (I am running an OC2.2) with a Find this and Replace for the above script.
              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!

              New member

              Posts

              Joined
              Mon Apr 28, 2014 4:20 pm

              Post by straightlight » Thu Mar 31, 2022 12:17 am

              evopixel wrote:
              Wed Mar 30, 2022 11:35 pm
              straightlight wrote:
              Tue Mar 29, 2022 9:05 pm
              evopixel wrote:
              Tue Mar 29, 2022 5:50 pm
              Is 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!
                  OC version. You'd need to modify your catalog/controller/tool/image.php and admin/controller/tool/image.php file where this line:

                  Code: Select all

                  $image->resize($width, $height);
                  
                  could become:

                  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);
                  |
                  
                  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.
                  So basically create an OCMOD (I am running an OC2.2) with a Find this and Replace for the above script.
                  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.

                  Dedication and passion goes to those who are able to push and merge a project.

                  Regards,
                  Straightlight
                  Programmer / Opencart Tester


                  Legendary Member

                  Posts

                  Joined
                  Mon Nov 14, 2011 11:38 pm
                  Location - Canada, ON

                  Post by sw!tch » Thu Mar 31, 2022 1:39 am

                  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'));
                  
                  ^ Product image sizes are resized and cached based on the theme image settings and can be changed dynamic, so what you want to do won’t work by default without additional modification.

                  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!


                  Active Member

                  Posts

                  Joined
                  Sat Apr 28, 2012 2:32 pm

                  Post by evopixel » Thu Mar 31, 2022 8:40 pm

                  Besides 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 :D
                  If it was a handful that would be fine, but it's in excess of 10000 images...

                  Thank you's!

                  New member

                  Posts

                  Joined
                  Mon Apr 28, 2014 4:20 pm

                  Post by straightlight » Thu Mar 31, 2022 9:31 pm

                  evopixel wrote:
                  Thu Mar 31, 2022 8:40 pm
                  Besides 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 :D
                  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.

                  Dedication and passion goes to those who are able to push and merge a project.

                  Regards,
                  Straightlight
                  Programmer / Opencart Tester


                  Legendary Member

                  Posts

                  Joined
                  Mon Nov 14, 2011 11:38 pm
                  Location - Canada, ON

                  Post by VTA NS » Fri Apr 01, 2022 1:50 am

                  Another perspective - is it possible (and how) to change the initial system picture upload size value from 500x500 to 800x800 (bigger pictures usually don't fit in the kb size)?

                  Newbie

                  Posts

                  Joined
                  Tue Mar 22, 2022 9:59 pm

                  Post by straightlight » Fri Apr 01, 2022 3:55 am

                  VTA NS wrote:
                  Fri Apr 01, 2022 1:50 am
                  Another perspective - is it possible (and how) to change the initial system picture upload size value from 500x500 to 800x800 (bigger pictures usually don't fit in the kb size)?
                  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


                  Legendary Member

                  Posts

                  Joined
                  Mon Nov 14, 2011 11:38 pm
                  Location - Canada, ON

                  Post by evopixel » Tue Jun 07, 2022 6:11 pm

                  straightlight wrote:
                  Thu Mar 31, 2022 12:17 am
                  evopixel wrote:
                  Wed Mar 30, 2022 11:35 pm
                  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:

                  Code: Select all

                  $image->resize($width, $height);
                  
                  could become:

                  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);
                  |
                  
                  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.
                  So basically create an OCMOD (I am running an OC2.2) with a Find this and Replace for the above script.
                  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.
                  #################################################

                  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;
                  		}
                  	}
                  }
                  Any ideas would be greatly appreciated :))

                  New member

                  Posts

                  Joined
                  Mon Apr 28, 2014 4:20 pm
                  Who is online

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