Not signed in (Sign In)

Vanilla 1.1.4 is a product of Lussumo. More Information: Documentation, Community Support.


    • CommentAuthorgilray
    • CommentTimeOct 26th 2006
     
    Is there a way to read all your images in a folder and then have a watermark automaticly added to the images in that folder?

    thanks,
    • CommentAuthorprogrammer
    • CommentTimeOct 26th 2006
     
    Create a new PNG image in photoshop with transparency. Leave the background transparent so

    it doesn't block the image below it when it's used as a watermark.

    Use this code to watermark the images...this assumes they are JPEG. If they are not, simply

    change imagecreatefromjpeg to imagecreatefromgif (for gif files) or imagecreatefrompng (for

    png files).

    <?

    $imagedir = "yourdirectorypath";
    $watermarklocation = "/home/you/watermark.png";

    $dir = opendir($dir);
    while(($file = readdir($dir)) !== false) {
    if ($file != '.' && $file != '..' && is_dir($file) == false) $files[] =

    $file;
    }

    foreach ($files as $key => $path) {
    $img = imagecreatefromjpeg($imagedir . $path);
    $wmHandle = imagecreatefrompng($watermarklocation);
    imageAlphaBlending($wmHandle, false);
    imageSaveAlpha($wmHandle, true);
    $wmWidth=imageSX($wmHandle);
    $wmHeight=imageSY($wmHandle);

    $dest_x = $img - $wmWidth - 1;
    $dest_y = $img - $wmHeight - 1;

    imagecopy($img, $wmHandle, $dest_x, $dest_y, 0, 0, $wmWidth, $wmHeight);
    imagejpeg($img, 90, $imagedir . "water_$path");
    }


    ?>