Jump to content

i have a challenge: how to put watermark just in the COVER images?


fernandokerber

Recommended Posts

Hi guys.

 

I need to put the watermark just in the Cover images...

 

 

Each of my products has two images and i want to apply the watermark just in the cover images.

 

Any idea?

 

I think i need to get the cover image path... but how?

 

 

 

 

In this function extracted from watermark.php I need to set the Cover image path in $file_base and $new_file, correct?

 

How could I do that?

 

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;
}

Edited by fernandokerber (see edit history)
Link to comment
Share on other sites

Hi,

 

I believe you would need to use

 

$image->cover

 

to find if the image is a cover image or not

 

maybe this would work:

 

public function hookwatermark($params)
{
 global $smarty;
 $image = new Image($params['id_image']);
 $image->id_product = $params['id_product'];
 if ($image->cover) {
  //$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;
 } else{
  $return = false;
 }
}

 

Hope it does. I could be totally wrong but maybe it will help

  • Like 1
Link to comment
Share on other sites

Hi,

 

I believe you would need to use

 

$image->cover

 

to find if the image is a cover image or not

 

maybe this would work:

 

public function hookwatermark($params)
{
 global $smarty;
 $image = new Image($params['id_image']);
 $image->id_product = $params['id_product'];
 if ($image->cover) {
  //$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;
 } else{
  $return = false;
 }
}

 

Hope it does. I could be totally wrong but maybe it will help

 

PERFECT!!!!

 

worked like a charm!!!

 

thank you very much!!!

 

 

I'm so happy

Link to comment
Share on other sites

Great, glad to have helped, not sure if that is the best way to go about it but it seemed like the most simple and less intrusive fix.

 

Yes.. it worked and this is the most important..

 

I was thinking about create a new image type for the cover images in Preference>Images. So we should have 'home images', 'large images', 'small images', 'thickbox images', ... , and the 'cover images'...

 

thus we could apply the watermark just to the "cover images" type.... And in the same way we could regenerate just the "cover images"...

 

I think that would be a nice approach but your solution worked great for me!

 

thanks again

Edited by fernandokerber (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...