jonp has asked for the wisdom of the Perl Monks concerning the following question:

Monks,
I thought someone out there might know how to do this. I am trying to organize some images for my work.
I need to write a script that will export 2 images to the same photoshop (.psd) file. What I have is a whole bunch of directories, each containing 2 gif images. So I need to take the 2 gif images from each directory and put them in the same psd file. I really am not sure how this could be done, but if anyone has any ideas it would really help.
Thanks for your help,
Jon

Replies are listed 'Best First'.
Re: Exporting images
by rokadave (Sexton) on Sep 20, 2005 at 18:17 UTC
    Use ImageMagick. It is really powerful. ImageMagick can be controlled with perl, using the module Image::Magick. In FC4 this can be installed with "yum install ImageMagick-perl"

    You weren't specific about how you'd like the images combined. I'll let you play with the different imagemagick options. Here's some code to get you started.

    #!/usr/bin/perl use warnings; use strict; use Image::Magick; my $image1=new Image::Magick; $image1->Read("dir1/1.gif"); my $image2=new Image::Magick; $image2->Read("dir1/2.gif"); $image1->Composite(image=>$image2,compose=>'plus'); $image1->Write("dir1.psd");
Re: Exporting images
by halley (Prior) on Sep 20, 2005 at 18:06 UTC
    This has nothing to do with Perl.

    However, check out ImageMagick http://www.imagemagick.org/ for some command-line tools and even a set of Perl bindings to let you script a solution.

    Further, I recommend you work with portable image formats, not .PSD files. Sure, load the file into Photoshop if you must, but consider TIFF or PNG or some other format if possible for your application. You weren't clear if you wanted to import images as layers, but PSD isn't the only format which can help you there.

    --
    [ e d @ h a l l e y . c c ]

      I downloaded imageMagick and have it working to append images together. This is good, but I do want to import the images as separate layers, so that they are independent and I can rearrange them. Do you know how to do this? I have checked the user guide, but it doesn't seem to tell how to do this.
      Thanks for your help, Jon
        I thought it would be easy, but I'm having trouble with layers too. I did get it to work saving the output as a gif, so I wonder if I don't have all the support libraries to write multi-layer psds.
        #!/usr/bin/perl use warnings; use strict; use Image::Magick; my $image1=new Image::Magick; $image1->Read("dir1/1.gif","dir1/2.gif"); $image1->Write("dir1.gif");
        I'm opening this multi-layer-gif in gimp. I don't know if photoshop will open it the same way.

        Update: .tif also works as a multi-layer file, at least you won't have to combine both images down to an 8 bit pallette.