Results 1 to 3 of 3

Thread: Another Photoshop Batch Question...

  1. #1
    You do realize by 'gay' I mean a man who has sex with other men?
    Join Date
    Oct 2003
    Location
    New Orleans, Louisiana.
    Posts
    21,635

    I Wonder? Another Photoshop Batch Question...

    Does anyone know how i would go about placing an image on top of an existing image in the exact same place for about 500 files?

    Basically, i have a bunch of thumbnails, all 200x200 and i also have a small media player graphic that i want to put on the bottom of all these thumbs so they look like 'movie clips'.

    Anyone know how i would set this up as a Photoshop batch job instead of having to manually place the graphic on the thumbs myself?

    Regards,

    Lee


  2. #2
    I am not gay but I have slept with some guys who are
    Join Date
    Oct 2006
    Posts
    378
    Well, I've never done it, but it should be easy.

    Easy enough to test doing it anyway.

    You just want to put a video bar under the thumb?

    Open a thumb in photoshop. Open the video bar. make sure the video bar is the desired size.

    Start recording an action.

    Increase the canvas size by the height of the video bar, anchoring the canvas at the top. This will create a blank space the height of the bar under the thumb.

    copy the video bar and paste it into the thumb. move it to the desired position.

    Stop the recording.

    That should then do the exact same thing to any number of thumbs - assuming they are all the same size. I would run it off the screen, not directed at a folder - but you could add an extra part of the action, that lets you run it on a folder, that opens the required video bar, copys it, and closes it again. Easier to open it once and run it off the screen.

    ("off the screen" means to run it on files that you have dragged and dropped into photoshop - basically, to run it on opened thumbs.)

    You could do the same thing to paste a thumb inside a video player frame.

    I haven't tested this, but feel certain that with a bit of trial and error it will work.

    groan - I guess I should test it before saying it's possible, hahahha.


  3. #3
    Red Axe Programmers
    Join Date
    May 2008
    Location
    Amsterdam
    Posts
    10
    Hi Lee,

    You could do this with the following php code on your sever. Which I've written most of it. It needs to GD library to be installed on the server.

    Store the code below in a php file:
    PHP Code:
    <?php

    /**
    @description                        places a overlay on top of an image
    @param resource $image                the image resource
    @param resource $overlay                the overlay resource
    @param integer $x                    x position of the overlay
    @param integer $y                    y position of the overlay
    @param integer $opacity                the amount of opacity of the over lay
    @return resource                        the image resource with the overlay on top
    **/
    function placeOverLay($image$overlay$x$y$opacity) {

      
    // getting the overlay width
      
    $w imagesx($overlay);
      
    // getting the overlay height
      
    $h imagesy($overlay);
     
      
    // creating a cut resource
      
    $cut imagecreatetruecolor($w$h);
      
    // copying that section of the background to the cut
      
    imagecopy($cut$image00$x$y$w$h);
      
    // inverting the opacity
      
    $opacity 100 $opacity;
     
      
    // placing the watermark now
      
    imagecopy($image$overlay$x$y00$w$h);
      
    imagecopymerge($image$cut$x$y00$w$h$opacity);
        return 
    $image;
    }




    /**
    @description                            gets the content insisde a directory
    @param string $path                        the directory were the source images are located
    @param string $savePath                    the directory were the image with the overlay need to be stored
    @param string $overLayImage                the image that needs to be laid over the source image
    @param string $x                            the coordinate x of the overlay image seen from the source image
    @param string $y                            the coordinate y of the overlay image seen from the source image
    @param string $opacity                        the tranparancy of the overlaid image
    @param string $preFix                        the prefix that's added on the end of the source image    $filenameSourceImage[$prefix].extension
                                                                            when you don't want it give '' or just leave this parameter out
    @return string                            the error messages are given as error message on the screen output
                                                                            when done a summarry will be given
    */
    function batchPlaceOverLay($path$savePath$overLayImage$x$y$opacity$preFix='') {
            
        
    $savePath = (substr($savePath, -1) == "/") ? substr($savePath0, -1) : $savePath;
        
    $path = (substr($path, -1) == "/") ? substr($path0, -1) : $path;

        if(!
    is_dir($path))      exit('$path['.$path.'] is not a directory<br>');
        if(!
    is_readable($path))      exit('$path['.$path.'] is not readable<br>');

        if(!
    is_dir($savePath))      exit('$savePath['.$savePath.'] is not a directory<br>');
        if(!
    is_readable($savePath))      exit('$savePath['.$savePath.'] is not readable<br>');
        if(!
    is_writable($savePath))          exit('$savePath['.$savePath.'] is not writeable<br>');

        if(!
    file_exists($overLayImage))          exit('$overLayImage['.$overLayImage.'] does not exists<br>');
        if(!
    is_readable($overLayImage))          exit('$overLayImage['.$overLayImage.'] is not readable<br>');

        
    $path .= "/";
        
    $savePath .= "/";

        
    $imageResourceOverLay getImageResource($overLayImage);
        if(!
    $imageResourceOverLay)        exit('could not create an image identifier of $overLayImage['.$overLayImage.']<br>');
        
        if(
    $handle=opendir($path)) {    
            
            
    $countSouceImages 0;
            
    $countCreatedImages 0;
        while(
    false!==($entry=readdir($handle))) {
                if(!
    ereg("^([.]{1,2})$"$entry
                && 
    is_file($path.$entry)
                && 
    $path.$entry!=$overLayImage) {
                    
                    
    $imageResourceSource getImageResource($path $entry);
                    if(
    $imageResourceSource!==false) {
                        
                        
    $countSouceImages++;
                        
    $extension getExtensionFile($path $entry);
                        
    $imageResourceFinal placeOverLay($imageResourceSource$imageResourceOverLay$x$y$opacity);
                        
                        
    $entry str_replace('.'.$extension$preFix.'.'.$extension$entry);
                        switch(
    $extension) {

                            case 
    'gif':
                                
    $writeFile = @imagegif($imageResourceFinal$savePath $entry);  
                                break;

                            case 
    'jpg':
                                
    $writeFile = @imagejpeg($imageResourceFinal$savePath $entry);
                                break;

                            case 
    'png':
                                
    $writeFile = @imagepng($imageResourceFinal$savePath $entry);
                                break;


                        }
                        @
    imagedestroy($imageResourceFinal);

                        if(
    $writeFile===false
                            echo 
    'Failed to create new image['.$path.$entry.']<br>';
                        else        
    $countCreatedImages++;

                    }
                }
          }
            echo 
    "total source images in " $path ":" $countSouceImages "<br>";
            echo 
    "total created images in " $savePath ":" $countSouceImages "<br>";

        } 
    }


    /**
    @description                gets the image identifier of $image
    @param $string $image            (absolute/relative)path to the image with the filename
    @return boolean,resource        false on failure, the image resource identifier on success
    @note                                                can only handle a jpg, gif or png image
    */
    function getImageResource($image) {

        
    $extension getExtensionFile($image);
        if(!
    $extension)        return false;

        
    $imageResource false;
        switch(
    $extension) {

            case 
    'gif':
                
    $imageResource = @imagecreatefromgif($image);
                break;

            case 
    'jpg':
                
    $imageResource = @imagecreatefromjpeg($image);
                break;

            case 
    'png':
                
    $imageResource = @imagecreatefrompng($image);
                break;

        }
        return 
    $imageResource;

    }


    /**
    @description            gets the file extension form $filename
    @param string $filename    name of the file
    @return string, boolean        the extension without the . in front, false on failure
    */
    function getExtensionFile($filename) {

        if(
    ereg('.+\.(.+)'trim($filename), $matches))        return $matches[1];
        return 
    false;

    }


    ?>
    At the bottom of this file you can give the following command
    PHP Code:
    batchPlaceOverLay($path$savePath$overLayImage$x$y$opacity$preFix=''
    At $path you fill in the path to the images related or absolute like
    'images/' or '/home/www/sitename/htdocs/images/'
    At $savePath you fill in the path to were the new images should be saved, same way as done at $path.
    At $overLayImage you give the image you want to put on top of the source image. Something like '/home/www/sitename/htdocs/images/overlay.jpg' or
    'overlay/overlay1.jpg'
    At $x and $y you give the coordinates of the position the overlayed image should start. $x and $y are coordinates related to the source image. 0, 0 will put the overlayed at the left top of the source image.
    At $opicty you give the amount of transparancy that should be given to the
    overlayed images. For example when given 100 the overlayed image will not have any transparancy, when 0 you won't see the overlayed image because its complete tranparent.
    At $prefix you give a possible prefix to the filename of the newly created image. If the source is called 'image.jpg' and the prefix is '_new' then the new image is called image_new.jpg. Leave this out when you don't want it or
    put in ''

    An example:
    PHP Code:
    batchPlaceOverLay('images/''result/''overlay/video2.jpg'0050'_new'); 
    The script can handle jpg, gif and png. I hope it will help you out and I wasn't to technical. Working with this script is ofcourse at own risk

    Best Wishes,
    Arian


Posting Permissions

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