Page 1 of 1
Watermark to thumbnails picture of product
Posted: 16 Jan 2023, 19:11
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
Item view
Zoom view
Re: Watermark to thumbnails picture of product
Posted: 17 Jan 2023, 17:43
by Jan
Re: Watermark to thumbnails picture of product
Posted: 12 Feb 2023, 10:14
by jpeters
nice, can you explain your current way of working / solution that you use?
Re: Watermark to thumbnails picture of product
Posted: 27 Mar 2023, 14:59
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
Re: Watermark to thumbnails picture of product
Posted: 28 Mar 2023, 12:10
by Jan
Hi, thank you for the info.
Jan
Re: Watermark to thumbnails picture of product
Posted: 28 Mar 2023, 12:27
by jpeters
can you share the php script and way of working you currently do. perhaps some "smart" integration is possible / automation.
Re: Watermark to thumbnails picture of product
Posted: 28 Mar 2023, 14:05
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);
?>
Re: Watermark to thumbnails picture of product
Posted: 28 Mar 2023, 14:44
by Jan
Hi, thank you.