I am trying to apply watermark on my all image with in folder.For get working this i am using this line of code.
<?php
function endsWith($currentString, $target)
{
$length = strlen($target);
if ($length == 0) {
return true;
}
return (substr($currentString, -$length) === $target);
}
if ($handle = opendir('images')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
if (endsWith($entry,'.jpg')==0){
echo "<br/> $entry: is ignored.
";
continue;
}
echo "<br/> $entry
";
$image_path = "images/".$entry;
$watermark = imagecreatefrompng('wa/ap.png');
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$image = imagecreatefromjpeg($image_path);
if ($image === false) {
return false;
}
$tragetedImageSize = getImageSize($image_path);
$wmPositionX = $tragetedImageSize[0]- $watermark_width - 6;
$wmPositionY = $tragetedImageSize[1] - $watermark_height - 6;
imagealphablending($image, true);
imagealphablending($watermark, true);
imagecopy($image, $watermark, $wmPositionX, $wmPositionY, 0, 0, $watermark_width, $watermark_height);
imagejpeg($image, "images/$entry");
imagedestroy($image);
imagedestroy($watermark);
}
}
closedir($handle);
}
?>
this code working fine. But now If add a new image in this folder and again run my php code then other image which alredy watermarked last time. I want skip those image which is watermarked last time .
Extra :: One more this if images folder have more sub folder then what code need tobe changed ?
Thanks