1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Bulk watermark

Discussion in 'Photoshop' started by Python, Feb 2, 2010.

  1. #1
    Hi,
    I have a whole bunch of images, a folder full, all of various sizes. I need to batch watermark them all.

    I know how to do this in Photoshop however I'd like to choose exactly where the watermark should go - it needs to go in the far right bottom corner of every one. All I've been able to achieve is to slap a watermark dead center.

    Can this be done in Photoshop CS4? If so, how? If not, how else could I do this?

    Thanks!
     
    Python, Feb 2, 2010 IP
  2. LeetPCUser

    LeetPCUser Peon

    Messages:
    711
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The only way I know of doing it is opening them one at a time and positioning the watermark. You can copy the watermark layer and paste it over all the images, align it, set the opacity and save them.
     
    LeetPCUser, Feb 4, 2010 IP
  3. Python

    Python Well-Known Member

    Messages:
    680
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    120
    #3
    That's a real paint though having to do them one by one. I have hundreds of images I need this done.
     
    Python, Feb 5, 2010 IP
  4. thesamemanhal

    thesamemanhal Active Member

    Messages:
    1,126
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    55
    #4
    I have exactly the same problem, mine is even worse, images (jpg) are all located in a bunch of sub-directories , please any help ?
     
    thesamemanhal, Feb 5, 2010 IP
  5. Python

    Python Well-Known Member

    Messages:
    680
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    120
    #5
    I suppose I could write a PHP script to do it, but I was hoping for something more robust.
     
    Python, Feb 5, 2010 IP
  6. thesamemanhal

    thesamemanhal Active Member

    Messages:
    1,126
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    55
    #6
    Python, have you tried to use a software for this, I was thinking to use watermarkfactory program, but I am not sure yet
     
    thesamemanhal, Feb 5, 2010 IP
  7. Python

    Python Well-Known Member

    Messages:
    680
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    120
    #7
    I have not found any software which can do this. I've given up on looking to be honest, I'll probably just use a PHP script.
     
    Python, Feb 5, 2010 IP
  8. kmofo

    kmofo Active Member

    Messages:
    442
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    85
    #8
    First press Alt F9 to bring out actions. Then click the "New" button, fill out name, etc. Open a file. Click "Record". Add the watermark. Click "Stop".

    Now go to File->Automate->Batch and do your watermarking using the action defined earlier.

    LE: That's for CS3, but I guess it should work with CS4 also.
     
    kmofo, Feb 5, 2010 IP
  9. Python

    Python Well-Known Member

    Messages:
    680
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    120
    #9
    Yes, but that won't put it into the bottom right hand corner for every image.
     
    Python, Feb 5, 2010 IP
  10. thesamemanhal

    thesamemanhal Active Member

    Messages:
    1,126
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    55
  11. dabzo

    dabzo Peon

    Messages:
    188
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Alrighty, in photoshop... goto actions, new action... then... with your branding on the clipboard, paste it, select the whole stage, then use your align tool (Don't do this by hand, it is a relative action and ...) Align it using the align tools in your header-bar... don't just click it and drop it somewhere.

    Then, save as...

    Then go and click, file>>automate, choose your folder, set your filters and click GO:... PS wil "batch" your images with the branding.

    This is also great for auto-levels, cropping, resizing etc.

    ..Edit, just read your last post and will clarify further. once you have pasted, select the WHOLE stage... then, click your selction tool (the arrow with the square thingie, usually top on the right of your tools) *dont' click anything*... see those options up at the top? with the lines and boxes, they are different ways to align your selection, in this case what you have just pasted on the layer... from there, just aling to the absolute right and bottom... Now, for even more fun, if you have black text and a white BG... try setting the layer to "multiply"... no more white bg... but it still give you your spacing from the edge of the page... Neat and tidy.

    Hope that helped,
    Take care!
     
    Last edited: Feb 15, 2010
    dabzo, Feb 15, 2010 IP
  12. Python

    Python Well-Known Member

    Messages:
    680
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    120
    #12
    Great! I got it working, thanks!
     
    Python, Feb 17, 2010 IP
  13. flaminbo

    flaminbo Well-Known Member

    Messages:
    274
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    160
    #13
    Now this isnt my coding,it is the work of my friend Lite,he is a awesome coder in php and more,all thanks go to him for this code,hope this is what you are looking for

    Resize to browser
    <?php
        include 'imageBox.class.php';
    
        $Image = new imageBox("path/to/file.png");
        $Image->resize(640,480)->toBrowser();
    ?> 
    PHP:
    Resize & Rotate to browser
    <?php
        include 'imageBox.class.php';
    
        $Image = new imageBox("path/to/file.png");
        $Image->resize(640,480)->rotate(75)->toBrowser();
    ?> 
    PHP:
    Resize to file
    <?php
        include 'imageBox.class.php';
    
        $Image = new imageBox("path/to/file.png");
        $Image->resize(640,480)->rotate(75)->saveAs("save/as/image.png");
    
        //Note: you change the extention when saving
        //$Image->resize(640,480)->rotate(75)->saveAs("save/as/image.gif");
        //$Image->resize(640,480)->rotate(75)->saveAs("save/as/image.jpg");
    ?> 
    PHP:
    The whole works

    <?php
        include 'imageBox.class.php';
    
        $Image = new imageBox("path/to/file.png");
        $Image
            ->resize(320,320)
            ->text("Hello World!","FFF",10,40,40)
            ->watermark("images/myWatermark.png","br")
            ->saveAs(dirname(__FILE__).'/images/the_file.png',75)
            ->toBrowser('jpg',100);
            //This is saving the file and then outputting it to the browser
            //Note: when saving as jpg you can set the 2nd parameter for quality 0-100% 
    ?> 
    PHP:

    Heres the core class file
    
    <?php
    class imageBox{
        
        /*Private*/
        private $mainFile,$mainImage,$mainInfo;
        
        /*
        *** Constructor (Takes a local filename)
        */
        function __construct($file){
            $this->mainFile = $file;
            //Check to see if file exists
            if(!file_exists($this->mainFile)){
                trigger_error("Image does not exists (".basename($this->mainFile).")",E_USER_ERROR);
            }
            
            //Other wise lets gather some info
            $this->mainInfo = $this->_gatherFileInfo($this->mainFile);
            
            //Now we have to create a new image object
            $this->mainImage = $this->_createNewImage($this->mainFile);
        }
        
        /*
        *    Public
        *    Note: All public methods should return $this unless there output methods / final methods
        **/
        
        public function text($text,$color = '000000',$size = 5,$x = 0, $y = 0){
            $rgb = $this->html2rgb($color);
            imagestring($this->mainImage, $size, $x, $y, $text, imagecolorallocate($this->mainImage,$rgb[0],$rgb[1],$rgb[2]));
            //Return the context
            return $this;
        }
        
        public function rotate($degree, $color = 'FFFFFF'){
            //Get hex for colour code
            $rgb = $this->html2rgb($color);
            
            //Chgeck the degree is in range
            $degree = (($degree > 0 && $degree < 360) ? $degree : 180);
            
            //rotate the image accordingly
            $this->mainImage = imagerotate($this->mainImage,$degree,imagecolorallocate($this->mainImage,$rgb[0],$rgb[1],$rgb[2]));
            
            //Update the mainImage Dx
            $this->mainInfo->width    = imagesx($this->mainImage);
            $this->mainInfo->height    = imagesy($this->mainImage);
            
            //Return the context
            return $this;
        }
    
        public function watermark($file,$position = 'bottomright'){
            (    /*Check and create watermark from file*/
                file_exists($file)
                ?    $this->watermark = $this->_createNewImage($file)
                :    trigger_error("imageBox:: Unable to open watermark file (".basename($file).")",E_USER_ERROR)
            );
            //Get watermark sizes
            $this->watermark_info = $this->_gatherFileInfo($file);
            
            //Set the hieghts
            
            //Lets get the posstion of the where we want to place the watermark
            switch($position){
                case 'topleft':case 'tl':
                    $this->watermark_pos_x = 3;
                    $this->watermark_pos_y = 3;
                break;
                case 'topright':case 'tr':
                    $this->watermark_pos_x = ($this->mainInfo->width - $this->watermark_info->width)-3;
                    $this->watermark_pos_y = 3;
                    break;
                case 'bottomleft':case 'bl':
                    $this->watermark_pos_x = -3;
                    $this->watermark_pos_y = ($this->mainInfo->height - $this->watermark_info->height)-3;
                break;
                case 'bottomright':case 'br':
                    $this->watermark_pos_x = ($this->mainInfo->width    - $this->watermark_info->width)-3;
                    $this->watermark_pos_y = ($this->mainInfo->height    - $this->watermark_info->height)-3;
                break;
                default:
                    $this->watermark_pos_x = 0;
                    $this->watermark_pos_y = ($this->mainInfo->height - $this->watermark_info->height)-3;
                break;
            }
            
            //Add the watermarked image to the mainImage
            imagecopy(
                $this->mainImage,
                $this->watermark,
                $this->watermark_pos_x,
                $this->watermark_pos_y,
                0,0,
                $this->watermark_info->width,
                $this->watermark_info->height
            );
            imagedestroy($this->watermark);
            
            //Return the context
            return $this;
        }
    
        public function resize($width = 640,$height = 480){
            
            //Setup scale
            $scale = min(
                         $width/$this->mainInfo->width,
                         $height/$this->mainInfo->height
                    );
                    
            if ($scale == 1){
                return $this; // no need to change
            }
    
            $new_width    =    ($this->mainInfo->width * $scale);
            $new_height    =    ($this->mainInfo->height * $scale);
            $xpos        =    (($width - $new_width) / 2);
               $ypos        =    (($height - $new_height) / 2);
            
            //Create a copy of the current image for changeover
            $this->imageBackup    = $this->mainImage;
            
            //Make new image with the Dx passed
            $this->mainImage    = imagecreatetruecolor($new_width,$new_height);
            
            //Create plain background
            $this->plain_bg = imagecolorallocate($this->mainImage,255,255,255);
            
            //Add the plain Background
            imagefilledrectangle($this->mainImage,0,0,$width,$height,$this->plain_bg);
            
            //Copy the main image to the newly sized image
            imagecopyresampled(
                $this->mainImage,$this->imageBackup,0,0,0,0,$new_width,$new_height,
                $this->mainInfo->width,$this->mainInfo->height
            );
            
            //Delete the old image
            imagedestroy($this->imageBackup);
            
            //Update the Dx for the mainImage
            $this->info->width  = $width;
            $this->info->height = $height;
            
            //Return the main object for streamlining
            return $this;
        }
        
        public function toBrowser($outputType = 'jpg',$quality = 100){
            //Send the file to browser and EXIT
            switch($outputType){
                case "gif":
                    header('Content-type: image/gif');
                    imagegif($this->mainImage,NULL);
                    exit;
                break;
                case "png":
                    header('Content-type: image/png');
                    imagepng($this->mainImage,NULL);
                break;
                case "jpg":case "jpeg":
                    header('Content-type: image/jpeg');
                    imagejpeg($this->mainImage,NULL, (int)$quality);
                    exit;
                break;
                default:
                    trigger_error("imageBox:: Unaable to output to browser, check output ext (".$outputType.")",E_USER_ERROR);
                break;
            }
        }
        
        public function saveAs($location,$quality = 100){
            $info = pathinfo($location);
            $extension = $info['extension'];
            
            switch($extension){
                case "gif":
                    imagegif($this->mainImage, $location);
                break;
                case "png":
                    imagepng($this->mainImage, $location);
                break;
                case "jpg":case "jpeg":
                    imagejpeg($this->mainImage, $location, $quality);
                break;
                default:
                    trigger_error("imageBox:: Unaable to save image, check save ext (".$extension.")",E_USER_ERROR);
                break;
            }
            return $this;
        }
        
        /*Private Functions*/
        private function _createNewImage($file){
            $info = $this->_gatherFileInfo($file);
            switch($info->mime){
                case "image/gif":
                    return imagecreatefromgif($file);
                break;
                case "image/png":
                    return imagecreatefrompng($file);
                break;
                case "image/jpg":
                case "image/jpeg":
                    return imagecreatefromjpeg($file);
                break;
                default:
                    trigger_error("imageBox:: Unable to load image into GD, Incorrect mime type (".$info->mime.")",E_USER_ERROR);
                break;
            }
        }
        
        private function _gatherFileInfo($file){
            $info = getimagesize($file);
            $this->tmp_info = new stdClass();
            
            /*Send the info to the stdClass*/
            $this->tmp_info->width    = $info[0];
            $this->tmp_info->height    = $info[1];
            $this->tmp_info->bits    = $info['bits'];
            $this->tmp_info->mime    = $info['mime'];        
            return $this->tmp_info;
        }
        
        private function html2rgb($color) {
            if ($color[0] == '#'){$color = substr($color, 1);}
            if(strlen($color) == 6){
                list($r, $g, $b) = array($color[0].$color[1],$color[2].$color[3],$color[4].$color[5]);
            }elseif(strlen($color) == 3){
                list($r, $g, $b) = array($color[0].$color[0],$color[1].$color[1],$color[2].$color[2]);
            }else{
                return array(hexdec("FF"),hexdec("FF"),hexdec("FF"));
            }
            return array(hexdec($r),hexdec($g),hexdec($b));
        }
        
        /*Destructor to remove the image*/
        function __destruct(){
            imagedestroy($this->mainImage);
        }
    }
    ?> 
    PHP:
     
    flaminbo, Feb 17, 2010 IP
  14. dabzo

    dabzo Peon

    Messages:
    188
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #14
    That's awesome!

    And hey, if you're ever having problems with "save as", just remember to flatten your image as a part of the recorded action.
     
    dabzo, Feb 17, 2010 IP
  15. this_is_it

    this_is_it Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    great tips..

    great tools..

    ;)
     
    this_is_it, Feb 18, 2010 IP
  16. rapidtroop

    rapidtroop Guest

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    u should try any watermaking software..
    mine r watermarkfactory..
     
    rapidtroop, Feb 28, 2010 IP