<?php
ini_set("max_execution_time", "3000");
$imgfolder = "downloadedimg";
$baseUrl = "$_SERVER[DOCUMENT_ROOT]";
$srcimgfolder = "$_SERVER[DOCUMENT_ROOT]/$imgfolder";
$files = scandir($srcimgfolder);
$files = array_slice($files, 2, sizeof($files));
function watermarkall($infile,$outfile){
$src = imagecreatefromjpeg($infile);
if (!$src)
return 0;
$w_src = imagesx($src);
$h_src = imagesy($src);
//watermark puts here.
$watermark = imagecreatefrompng("watermark.png");
$watermark_w = imagesx($watermark);
$watermark_h = imagesy($watermark);
imageAlphaBlending($watermark, false);
imageSaveAlpha($watermark, true);
imagecopy($src, $watermark, $w_src/2-$watermark_w/2, $h_src/2-$watermark_h/2, 0, 0,
$watermark_w, $watermark_h);
imagejpeg($src,$outfile,100);
imagedestroy($src);
return 1;
}
foreach($files as $row){
$infile = "$baseUrl/$imgfolder/$row";
$outfile = "$baseUrl/watermarked/$row";
watermarkall($infile,$outfile);
}
echo "Done!";
?>