You know... this thing called Google... http://php.net/manual/en/image.examples.merged-watermark.php http://runnable.com/UnF5hbIOBM91AAAb/how-to-add-watermark-to-an-image-with-gd-library-for-php I'm sure these methods can be tweaked to fit your needs
I tried the following code with the following errors, can you se what im doing wrong? :/ Notice: Undefined variable: image_in_folder in /home/mvafoto/gallery/test/test.php on line 20 Warning: Invalid argument supplied for foreach() in /home/mvafoto/gallery/test/test.php on line 20 <? error_reporting(E_ALL); ini_set('display_errors', 'on'); $dir_to_img='/'; $watermark = "watermark.png"; $dir_to_new_image='/watered/'; if(is_dir($dir_to_img)){ if($dir = opendir($dir_to_img)){ while(($archivo = readdir($dir)) !== false){ if($archivo != '.' && $archivo != '..' && $archivo != '.htaccess'){ if(substr($archivo, -4) == '.jpg' || substr($archivo, -4) == '.JPG') //only jpg files $image_in_folder[] = $archivo; } } closedir($dir); } } foreach ($image_in_folder as $imagen) { $im = imagecreatefrompng($watermark); $im2 = imagecreatefromjpeg($dir_to_img."/".$imagen); imagecopy($im2, $im, (imagesx($im2)/2)-(imagesx($im)/2), (imagesy($im2)/2)-(imagesy($im)/2), 0, 0, imagesx($im), imagesy($im)); if(!is_dir($dir_to_new_image)){ //save to another dir mkdir($dir_to_new_image, 0777, true); } imagejpeg($im2,"$dir_to_new_image/$imagen",90); imagedestroy($im); imagedestroy($im2); } ?> PHP:
Well, two questions, really. Are you trying to read root? Because that's what you're trying to open. Second, you should assign $image_in_folder to an array outside the loop. As I can see now, I'm guessing there are no images in the root folder, hence the $image_in_folder-array is never created, and the for each fails