Jump to content
Sign in to follow this  
Baby Moon

[CONTRIBUTION] Watermark improvement

Recommended Posts

My website has 4000 products, more than 28000 pictures, when I regenerate the image, it took long time, even time out.
After I read the source code, I realized that the regeneration and watermark did double jobs. Regeneration generate the pictures with the predefined types, then call the hooked watermark procedure. The hookwatermark procedure in the watermark.php regenerate a watermark image with -watermark surfix, then copy this watermark image as the predefined image types. So, the regeneration created images are over writed. And some the small size image we can't see the watermark clearly, because it's reduced the resolution.

I have modified the watermark.php, make it just merge the watermark image to the regeneration generated images. After this modification, the watermark can clearly displayed on all product images.

Code of watermark.php is below. I've remarked original code.

   public function hookwatermark($params)
   {
       global $smarty;
//        $file = _PS_PROD_IMG_DIR_.$params['id_product'].'-'.$params['id_image'].'-watermark.jpg';

       //first make a watermark image
//        $return = $this->watermarkByImage(_PS_PROD_IMG_DIR_.$params['id_product'].'-'.$params['id_image'].'.jpg',  dirname(__FILE__).'/watermark.gif', $file, 23, 0, 0, 'right');

       //go through file formats defined for watermark and resize them
       foreach($this->imageTypes as $imageType)
       {
           $file = _PS_PROD_IMG_DIR_.$params['id_product'].'-'.$params['id_image'].'-'.stripslashes($imageType['name']).'.jpg';
           $return = $this->watermarkByImage($file,  dirname(__FILE__).'/watermark.gif', $file, 23, 0, 0, 'right');
//            $newFile = _PS_PROD_IMG_DIR_.$params['id_product'].'-'.$params['id_image'].'-'.stripslashes($imageType['name']).'.jpg';
//            if (!imageResize($file, $newFile, intval($imageType['width']), intval($imageType['height'])))
//                $return = false;    
       }
       return $return;
   }

34694_PEhJWDgosryjl5314gtp_t

Share this post


Link to post
Share on other sites

Thank you for your contribution.

Just one thing :

Your script use the already resized image to put the watermark on it, it can cause some problems.

There is the optimised script and updated for revision "7541" of the file watermark.php :

public function hookwatermark($params)
{
 global $smarty;
 $image = new Image($params['id_image']);
 $image->id_product = $params['id_product'];
 //$file = _PS_PROD_IMG_DIR_.$image->getExistingImgPath().'-watermark.jpg';
 //first make a watermark image
 //$return = $this->watermarkByImage(_PS_PROD_IMG_DIR_.$image->getExistingImgPath().'.jpg',  dirname(__FILE__).'/watermark.gif', $file, 23, 0, 0, 'right');
 //go through file formats defined for watermark and resize them
 foreach($this->imageTypes as $imageType)
 {
  //image de base
  $file_base = _PS_PROD_IMG_DIR_.$image->getExistingImgPath().'.jpg';
  //image de la categorie en cours de traitement
  $newFile = _PS_PROD_IMG_DIR_.$image->getExistingImgPath().'-'.stripslashes($imageType['name']).'.jpg';
  //redimensionnement de l'image
  if (!imageResize($file_base, $newFile, (int)($imageType['width']), (int)($imageType['height'])))
  {
$return = false;
  }
  else
  {
//application du filigrane sur la categorie en cours de traitement
$return = $this->watermarkByImage($newFile,  dirname(__FILE__).'/watermark.gif', $newFile, 23, 0, 0, 'right');
  }
 }
 return $return;
}

It create a copy from original image, then put watermark on it.

  • Like 1

Share this post


Link to post
Share on other sites

Thank you for your contribution.

Just one thing :

Your script use the already resized image to put the watermark on it, it can cause some problems.

There is the optimised script and updated for revision "7541" of the file watermark.php :

public function hookwatermark($params)
{
 global $smarty;
 $image = new Image($params['id_image']);
 $image->id_product = $params['id_product'];
 //$file = _PS_PROD_IMG_DIR_.$image->getExistingImgPath().'-watermark.jpg';
 //first make a watermark image
 //$return = $this->watermarkByImage(_PS_PROD_IMG_DIR_.$image->getExistingImgPath().'.jpg',  dirname(__FILE__).'/watermark.gif', $file, 23, 0, 0, 'right');
 //go through file formats defined for watermark and resize them
 foreach($this->imageTypes as $imageType)
 {
  //image de base
  $file_base = _PS_PROD_IMG_DIR_.$image->getExistingImgPath().'.jpg';
  //image de la categorie en cours de traitement
  $newFile = _PS_PROD_IMG_DIR_.$image->getExistingImgPath().'-'.stripslashes($imageType['name']).'.jpg';
  //redimensionnement de l'image
  if (!imageResize($file_base, $newFile, (int)($imageType['width']), (int)($imageType['height'])))
  {
$return = false;
  }
  else
  {
//application du filigrane sur la categorie en cours de traitement
$return = $this->watermarkByImage($newFile,  dirname(__FILE__).'/watermark.gif', $newFile, 23, 0, 0, 'right');
  }
 }
 return $return;
}

It create a copy from original image, then put watermark on it.

 

can you help me editing this code to put watermark JUST on the cover image?

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More