Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2004
    Atlanta, GA

    Foreach help please

    i use this code to manually watermark images.

    composite -gravity center /home/missbot/public_html/images/watermark.png original_img.jpg processed_img.jpg

    how would i batch watermark an entire directory of .jpg image?

    maybe a for each shell statement or php. it's a onetime use script

    thanks in advance

  2. #2
    Join Date
    Aug 2004
    Tulsa, Oklahoma
    I'm not a PHP guy.. but this may help:
    Mike Bell
    Image Hosting

  3. #3
    Join Date
    Jul 2003
    How about this? The following snippet makes the following assumptions:

    * You have glob() (requires PHP 4.3.0+)
    * The files you want converted are named original_xxx.jpg where xxx is any valid filename character.
    * You have proper permissions to the image directory
    * You have proper permissions to execute commands from PHP (ie, safe_mode)
    * The files generated will be named processed_xxx.jpg
    * You are running this script from the images directory

    PHP Code:
    $convert_location '/usr/bin/convert';
    $watermark '/path/to/images/watermark.png';

        foreach (
    glob('original_*.jpg') as $filename)
    //Build the command
    $command $convert_location.' -gravity center ';
    $command .= $watermark.' '.$filename.' ';

    //Generate the filename
    $command .= $dir_name.'processed_'.substr($filename,strpos($filename,'_')+1,strpos($filename,'.')-1);
    Of course, this is alot easier with some shell scripting, but I'm very rusty when it comes to shell scripting.

    If this script deletes files, formats your computer, makes illicit eye-contact with your dog, I am not responsible.

    Use at your own risk, and test it on a folder before letting it loose on your images directory.
    Last edited by Burhan; 07-10-2005 at 09:34 AM.
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

  4. #4
    Join Date
    Oct 2003
    find /path/directory/ -type f -name "*.jpg" -exec /path/to/composite -gravity center /home/missbot/public_html/images/watermark.png {} {}_processed.jpg \;
    Last edited by aldee; 07-10-2005 at 02:22 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts