Total members 11889 |It is currently Fri Mar 29, 2024 2:06 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Adding watermark to all images in a folder using php
php code
<?php
// add watermark to your website photos.

// check if string end with specific substring
function endsWith($currentString, $target)
{
$length = strlen($target);
if ($length == 0) {
return true;
}

return (substr($currentString, -$length) === $target);
}
// Loop on all JPG image exists in a folder
if ($handle = opendir('user_images')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {

if (endsWith($entry,'.jpg')==0){
// Skip images that are not JPG
echo "<br/> $entry: is ignored.\n ";
continue;
}
// Just printing the image file name
echo "<br/> $entry\n ";


// setting the image path
$image_path = "./user_images/".$entry;

// creating png image of watermark
$watermark = imagecreatefrompng('watermark.png');

// getting dimensions of watermark image
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);


$image = imagecreatefromjpeg($image_path);
//something went wrong
if ($image === false) {
return false;
}
// getting the dimensions of original image
$tragetedImageSize = getImageSize($image_path);
// placing the watermark 6px from bottom and right
$wmPositionX = $tragetedImageSize[0]- $watermark_width - 6;
$wmPositionY = $tragetedImageSize[1] - $watermark_height - 6;
// blending the images together
imagealphablending($image, true);
imagealphablending($watermark, true);
// creating the new image with watermark on it,
imagecopy($image, $watermark, $wmPositionX, $wmPositionY, 0, 0, $watermark_width, $watermark_height);
// saving the created image into current directory
imagejpeg($image, "./$entry");
// Freeing memory
imagedestroy($image);
imagedestroy($watermark);

}
}
closedir($handle);
}
?>




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Adding watermark to all images in a folder
 java code for listing folder contents from remote folder     -  
 Sequence of Images , draw several images in a row     -  
 could you help me to deal with this watermark?     -  
 watermark in photoshop     -  
 digital watermark on image     -  
 adding padding to your text     -  
 Adding a New Node to contact.xml     -  
 adding abbreviations to your html     -  
 Need automatic adding to catalogs     -  
 Get all files in folder     -  



Topic Tags

PHP Graphics






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com