Jump to content

Regenerate Image only one product


Recommended Posts

5 hours ago, ndiaga said:

If  you  need  to  change  images  for  only  one  product  why  not  delete  old  images  and  upload  new  images  again?

because one product sometime have lot of image, its not real delete and upload again

 

5 hours ago, Prestachamps said:

Hi, 

I found this one which is probably close to what you're looking for. 

The module offers you the option to delete as well generate images on a  product level!

Hope it helps ;)

Module not exist now :-) Developer now support only PS 1.7.

 

If presta can regenerate all of image, maybe exist some simple command for regenerate only one product? Thanks for advice.

Link to comment
Share on other sites

I'm not sure about the developer, but when I checked everything was there ;)

Here is a Google cached version the page (just to tease him ;))

As you can see the modules was PS 1.6 ready ;)  Why did he deleted the post - frankly I don't care, and find a bit childish as it was recommended;)

 

screenshot-webcache.googleusercontent.com-2021.01.28-20_24_14.png

Link to comment
Share on other sites

Thanks a lot musicmaster. But script not work. When i try regenerate product image with any product id or regenerate image with any image id I got message  p413Image 2091 dir not Found. Image 2092 dir not Found. Image 2093 dir not Found. Remove existing is disabled so some images may have been skipped. end

i think script not work with classic image path system, only with new system with directory. i have classic image path system when all product image exist in only one directory p and have name as [product.id]-[image.id]-large(home.. etc.).jpg  for ex. 413-2093-home.jpg without any subdirectory.

 

Edited by www.bio-krby-kamna.cz (see edit history)
Link to comment
Share on other sites

on product-edit.php you have correct selection image directory 

 

	  { $legacy_images = get_configuration_value('PS_LEGACY_IMAGES');
   	    $base_uri = get_base_uri();
	  }
	  $imgsizing = 'style="width:'.$prod_imgwidth.'px; height:'.$prod_imgheight.'px;"';
	  $path = getpath($id_image);


	  if($legacy_images) // right select !!!

	  { $imgbase = $base_uri.'img/p/'.$id_product.'-'.$id_image;
		$imgdir = $base_uri.'img/p/';
		$localbase = $localpath.'/img/p/'.$id_product.'-'.$id_image;
		$localdir = $localpath.'/img/p/';
		$namebase = $id_product.'-'.$id_image;
	  }
	  else
	  { $imgbase = $base_uri.'img/p'.$path.'/'.$id_image;
		$imgdir = $base_uri.'img/p'.$path.'/';
		$localbase = $localpath.'/img/p'.$path.'/'.$id_image;
		$localdir = $localpath.'/img/p'.$path.'/';
		$namebase = $id_image;
	  }

on the other php section, script work only with one image file system without support Legacy

Edited by www.bio-krby-kamna.cz (see edit history)
Link to comment
Share on other sites

  • 2 years later...

Hi,

 

here is a solution to generate images for one product only, it use also watermark module:

<?php
// Include PrestaShop's configuration file
require_once(dirname(__FILE__).'/config/config.inc.php');
require_once(dirname(__FILE__).'/init.php');

// Set the product ID for which to regenerate thumbnails
$productId = YOUR_PRODUCT_ID; // Replace YOUR_PRODUCT_ID with the actual product ID

// Load the product
$product = new Product((int)$productId);

// Load the product's images
$images = $product->getImages((int)Configuration::get('PS_LANG_DEFAULT'));

// Regenerate thumbnails for each image of the product
foreach ($images as $image) {
    // Create new Image object
    $imageObj = new Image((int)$image['id_image']);

    // Define the types of images to regenerate (you can modify this array with the types you want)
    $imageTypes = ImageType::getImagesTypes('products');
    
    // Regenerate thumbnails for each image type
    foreach ($imageTypes as $imageType) {
        $newImagePath = _PS_PROD_IMG_DIR_.$imageObj->getExistingImgPath().'-'.$imageType['name'].'.'.$imageObj->image_format;

        // Resize image
        if (!ImageManager::resize(
            _PS_PROD_IMG_DIR_.$imageObj->getExistingImgPath().'.'.$imageObj->image_format,
            $newImagePath,
            (int)$imageType['width'],
            (int)$imageType['height']
        )) {
            // Handle errors
            echo 'Error regenerating thumbnail for image ID ' . $image['id_image'] . ' for type ' . $imageType['name'];
            continue;
        }
        
        // Apply watermark if the module is installed and enabled
        $watermarkModule = Module::getInstanceByName('watermark');
        if ($watermarkModule && $watermarkModule->active) {
            // Check if the method 'hookActionWatermark' exists in the watermark module
            if (method_exists($watermarkModule, 'hookActionWatermark')) {
                // Prepare the hook arguments
                $hookArgs = array(
                    'image_type' => $imageType['name'],
                    'id_image' => $imageObj->id,
                    'id_product' => $product->id
                );

                // Call the watermark hook
                $watermarkModule->hookActionWatermark($hookArgs);
            }
        }
    }
}
?>

 

Edited by jorge2800 (see edit history)
  • Thanks 1
Link to comment
Share on other sites

We have included this functionality in our Prestashop suite QuicKupdate - eg you are able to regenerate images for any number of products down to the product level. Additionally if you have a large number of products you will have a very speedy regeneration and not get a time out because the app does batch processing of the products you want to regenerate.

Attached how it looks:

Screenshot2023-11-02234803.thumb.png.ec7b34d5bbc82bb9681f0d5a5473d4dc.png

Edited by QuickUpdate.net (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...