Watermark to thumbnails picture of product

Phoca Cart - complex e-commerce extension
zucha.imz
Phoca Member
Phoca Member
Posts: 34
Joined: 03 Aug 2018, 13:53

Watermark to thumbnails picture of product

Post by zucha.imz »

Hi,

maybe a another feature request for consider.
I already have my solution for adding watermark picture, but to the future for others.

Would be very nice, have a possibility add a watermark for pictures of products. And setting for adding watermark to small, medium, large and original image.

For example, I use adding a watermark only for large image. Small and medium picture are use on list view of product (category view) without watermark. Large image is showed in item view ( and of course as OpenGraph image), but in use with ZOOMING plugin, zoom use original image without watermark.

This was a special request from customer, but maybe will be usable for others ...

Category view
Image

Item view
Image

Zoom view
Image

Tags:
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 47869
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Watermark to thumbnails picture of product

Post by Jan »

Hi,

added to feature request list
https://github.com/PhocaCz/PhocaCart/issues/144

Jan
If you find Phoca extensions useful, please support the project
jpeters
Phoca Professional
Phoca Professional
Posts: 225
Joined: 31 Dec 2020, 09:46

Re: Watermark to thumbnails picture of product

Post by jpeters »

nice, can you explain your current way of working / solution that you use?
zucha.imz
Phoca Member
Phoca Member
Posts: 34
Joined: 03 Aug 2018, 13:53

Re: Watermark to thumbnails picture of product

Post by zucha.imz »

I use a php script to add watermart to picture.
Script find all large thumb files and add watermark.
And this script run manualy after add new product images ...

That`s all
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 47869
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Watermark to thumbnails picture of product

Post by Jan »

Hi, thank you for the info.

Jan
If you find Phoca extensions useful, please support the project
jpeters
Phoca Professional
Phoca Professional
Posts: 225
Joined: 31 Dec 2020, 09:46

Re: Watermark to thumbnails picture of product

Post by jpeters »

can you share the php script and way of working you currently do. perhaps some "smart" integration is possible / automation.
zucha.imz
Phoca Member
Phoca Member
Posts: 34
Joined: 03 Aug 2018, 13:53

Re: Watermark to thumbnails picture of product

Post by zucha.imz »

Yes, I can share, code is ugly. Maybe need some code corections for you ...
I have script located in images/phocacartproducts/media.
Script search all dirs in current dir and search for files whitch contains string "phoca_thumbs_l"

Here is code ...

I hope this help somebody ...

Code: Select all

<?php

  // Give the Complete Path of the folder where you want to save the image	
  $folder=".";
  
  
function find_folder_thumb ($folder) {

    $dirs = array_diff(scandir($folder), array('.', '..', 'orig')); 
    
     foreach($dirs as $dir) {
         if(is_dir($dir)) {
            $thumbsdir = $dir . '/thumbs/';
            echo $thumbsdir;
            echo "\r\n";
            addwatermark ($thumbsdir);
         }
         
     }
    
}    
  
  
  
  
  
function addwatermark($folder) {
    
  $myfiles = array_diff(scandir($folder), array('.', '..', 'orig')); 
  $text = "phoca_thumb_l";    // !!! set part of filename, which is used to add watermark. For my purpose is used only large thumbs
  
  
  foreach($myfiles as $imgfile) {
      
        
        if (strpos($imgfile,$text) !== false) {

      // Set the thumbnail name
        $dir = $folder.'orig';
        if (!file_exists($dir)) {
            mkdir($dir, 0755, true);
        }
        
        $origimage=$dir. '/' .$imgfile;
        $thumbnail=$folder.$imgfile;
        
        if (!file_exists($origimage)) {         
          //echo 'TH: '.$thumbnail . '   OR: ' . $origimage;
          copy($thumbnail, $origimage);
        }
      
        // Load the mian image
        $source = imagecreatefromjpeg($dir. '/' .$imgfile);  
        
        // load the image you want to you want to be watermarked
        $watermark = imagecreatefrompng('AKSA_logo.png');  // filename of watermark - transparent PNG
        
        // get the width and height of the watermark image
        $water_width = imagesx($watermark);
        $water_height = imagesy($watermark);
        
         // get the width and height of the main image image
        $main_width = imagesx($source);
        $main_height = imagesy($source);
        
        // Set the dimension of the area you want to place your watermark we use 0
        // from x-axis and 0 from y-axis 
        
        $dime_x = ($main_width - $water_width)/2;  // center logo verticaly
        $dime_y = ($main_height - $water_height)/2; // center logo horizontaly

        // copy both the images
        imagecopy($source, $watermark, $dime_x, $dime_y, 0, 0, $water_width, $water_height);

        // Final processing Creating The Image
        imagejpeg($source, $thumbnail, 100);
        echo $thumbnail . " watermark added OK! \r\n";
  }

  }
  
}


find_folder_thumb ($folder);
?>
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 47869
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Watermark to thumbnails picture of product

Post by Jan »

Hi, thank you.
If you find Phoca extensions useful, please support the project
Post Reply