Need to watermark all photos in an folder

Hi,

Can someone please provide a full example of merging a watermark with every image in a certain directory?

I want to use my watermark.png file to watermark. I need to specify where the watermark is on the image.
LVL 3
Computer GuyAsked:
Who is Participating?
 
innotionentCommented:
Over here is a nice tutorial with about watermarking an image.
http://blogs.sitepoint.com/watermark-images-php/

You could adapt your code to either watermark on upload using an uploader script.
or watermark on display when you put it on a webpage.
<?php

header('content-type: image/jpeg');

$watermark = imagecreatefrompng('watermark.png');
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$image = imagecreatetruecolor($watermark_width, $watermark_height);
$image = imagecreatefromjpeg($_GET['src']);
$size = getimagesize($_GET['src']);
$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);

?>

Open in new window

0
 
teedo757Commented:
try downloading irfanview: (free)
http://www.irfanview.com/

then follow this tutorial on watermarking in irfranview
http://stampinjenp.blogspot.com/2007/02/how-to-watermark-in-irfanview.html
0
 
Computer GuyAuthor Commented:
Hi,

I'm actually looking to use a PHP script so I can watermark select accounts.

I'm going to have a check box in my admin area that will turn watermark on or off.

The PHP script will either process with a watermark or now
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
teedo757Commented:
0
 
teedo757Commented:
You will need to install a photo editing software like gimp or the one listed above (pixelpost) and you will pass the photo off to the editor via command line.
0
 
Chris HarteThaumaturgeCommented:
Re: the previous answer I gave you on water marking an image.

Read all the files in a directory using readdir

http://php.net/manual/en/function.readdir.php

and use a while loop to pass each one as an argument to a watermarking function.
0
 
Ray PaseurCommented:
This is not really a question - it's a need for application development, and for that you probably want to hire a professional developer.  We can answer parts of this, but it will ultimately be up to you to integrate the concepts and produce working code.

See example one on this page for the way to find all of the files with names that match a pattern:
http://php.net/manual/en/function.glob.php

From that you will have an array of file names.  Then you can use an iterator like foreach to access each element of the array.
http://php.net/manual/en/control-structures.foreach.php

You can use phpinfo() to see what image manipulation software is installed on your server.
http://php.net/manual/en/function.phpinfo.php

You can use something like this to add the watermark over the image (see code snippet).  This uses PNG images but the principles are equally applicable to JPG or other image formats.
http://www.laprbass.com/RAY_image_watermark.php

You can see the source images used in the demonstration here:
http://www.laprbass.com/RAY_add_watermark_source_image.png
http://www.laprbass.com/RAY_add_watermark_watermark_image.png

Best of luck with the project, ~Ray
<?php // RAY_image_watermark.php
error_reporting(E_ALL);

// LOCATION OF THE IMAGES (COULD COME IN FROM $_GET URL STRING)
$original = 'http://www.LAPRBass.com/RAY_add_watermark_source_image.png';
$h2o_mark = 'http://www.LAPRBass.com/RAY_add_watermark_watermark_image.png';

// READ THE IMAGE AND THE WATERMARK FILE
// MAN PAGE http://php.net/manual/en/function.imagecreatefrompng.php
$im = ImageCreateFromPNG($original);
$wm = ImageCreateFromPNG($h2o_mark);

// ADD WATERMARK
imagelogo($im, $wm, imagesx($im), imagesy($im), imagesx($wm), imagesy($wm));

// SHOW THE IMAGE
header('Content-type: image/png');
ImagePNG($im);

// A FUNCTION TO ADD THE LOGO WATERMARK
// SEE http://php.net/manual/en/function.imagealphablending.php#77085
function imagelogo (&$dst_image, $src_image, $dst_w, $dst_h, $src_w, $src_h)
{
    ImageAlphaBlending($dst_image,TRUE);
    ImageAlphaBlending($src_image,TRUE);
    ImageCopy($dst_image, $src_image, ($dst_w-$src_w), ($dst_h-$src_h), 0, 0, $src_w, $src_h);
}

Open in new window

0
 
Ray PaseurCommented:
@audiotech520: Are you sure that you meant to accept that answer?  Did you test the script at all?  I installed it and ran it here:
http://www.laprbass.com/RAY_temp_innotionent.php

Outputs:
Parse error: syntax error, unexpected '&' in /home/websitet/public_html/RAY_temp_innotionent.php on line 1

There are so many things wrong with that example, including using unfiltered external data and the expression of browser output before the header() statement, that I think EE may want to get this out of the PAQ.  I will ask a moderator to delete the question or re-open it so that you can dispose of it in some other way.

Best regards, ~Ray
0
 
innotionentCommented:
Thanks! Sorry I wasn't able to test that code.
I'm thinking the OP liked the link I sent also.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.