homepage Welcome to WebmasterWorld Guest from 54.197.110.151
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Watermarking Images from a Directory
PHP to Watermark
mvaz

5+ Year Member



 
Msg#: 3958330 posted 7:14 pm on Jul 23, 2009 (gmt 0)

Hello all,
I have this script which searches a directory and if found, displays all images in there.

However, I want these images to be watermarked with a little png file that I have as my watermark and stored in a directory.

I have come up with this script, but it throws out various errors. Please could the experienced review my code as advise where I have gone wrong.

Code:
foreach($img_name as $img) {
//echo "<p><img src='$img' /><br /></p>" ; This line displays the images perfectly. However, I want the code below to work for the watermark.

$img = "<img src='$img' />";

$watermark = imagecreatefrompng('D:/web/mysite/photos/Canadaso-Comblo-2008/watermark.png');
$watermark_width = imagesx($watermark); // Watermark's width
$watermark_height = imagesy($watermark); // Watermark's height
$image = imagecreatetruecolor($watermark_width, $watermark_height);

$image = imagecreatefromjpeg($img);
$size = getimagesize($img);

$dest_x = $size[0] - $watermark_width - 5;
$dest_y = $size[1] - $watermark_height - 5;

imagecopymerge($image, $watermark, $dest_x, $dest_y, 0,0, $watermark_width, $watermark_height, 100);
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);

//The below curly braces are continuation of pervious codes.
}
}
}
}

closedir($dir_list);

 

NomikOS

5+ Year Member



 
Msg#: 3958330 posted 3:23 am on Jul 24, 2009 (gmt 0)

maybe if you include these lines before imagejpeg($image);
header("Cache-Control: no-store, no-cache, must-revalidate"); 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header('Content-type: image/jpeg');

NomikOS

5+ Year Member



 
Msg#: 3958330 posted 3:33 am on Jul 24, 2009 (gmt 0)

i mean that you need 2 files: 
file 1:
...
foreach($img_name as $img) {
echo "<img src="create_image.php" />"
}
...

file 2 (create_image.php)
...
image process
headers
...


sasori

5+ Year Member



 
Msg#: 3958330 posted 9:11 pm on Jul 24, 2009 (gmt 0)

hmm, without getting into imagemagick and creating a new image, you might be able to do this in CSS, where you lay a div that contains the watermark over the image. There will be some backwards compatibility browser issues, but I've done similar things with excellent results.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved