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);
?>