Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

using Photoshop via Perl

by reneeb (Chaplain)
on Dec 27, 2004 at 11:47 UTC ( [id://417531]=perlquestion: print w/replies, xml ) Need Help??

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

Hi Monks,

I try to resize images with Adobe Photoshop using Win32::OLE. I've written the following script:

#! /usr/bin/perl use strict; use warnings; use Win32::OLE; use Win32::OLE::Const 'Adobe Photoshop'; my $image_file = './atemschutzmaske.jpg'; # start photoshop my $ps = Win32::OLE->new('Photoshop.Application') or die $!; $ps->{Visible} = 0; # open image my $desc = $ps->MakeDescriptor(); my $control = $ps->MakeControlObject(); $desc->PutPath(phKeyNull,$image_file); $control->Play(phEventOpen,$desc,phDialogSilent); # autolevels $desc = $ps->MakeDescriptor(); $control = $ps->MakeControlObject(); $desc->PutBoolean(phKeyAuto, 1); $control->Play(phEventLevels,$desc,phDialogSilent); # resize to 400 * 400 px $desc = $ps->MakeDescriptor(); $control = $ps->MakeControlObject(); $desc->PutUnitDouble(phKeyWidth, phUnitPixels, 400); $desc->PutBoolean(phKeyConstrainProportions, 1); $desc->PutEnumerated(phKeyInterfaceIconFrameDimmed,phTypeInterpolation +,phEnumBicubic); $control->Play(phEventImageSize,$desc,phDialogSilent); $control = $ps->MakeControlObject(); my $d1 = $ps->MakeDescriptor(); my $d2 = $ps->MakeDescriptor(); $d2->PutEnumerated(phKeyPNGInterlaceType,phTypePNGInterlaceType,phEnum +PNGInterlaceNone); $d2->PutEnumerated(phKeyPNGFilter,phTypePNGFilter,phEnumPNGFilterAdapt +ive); $d1->PutObject(phKeyAs,phClassPNGFormat,$d2); (my $outfile = $image_file) =~ s/\.jpg/_thumb.png/; print $outfile,"\n"; $d1->PutPath(phKeyIn,$outfile); $d1->PutBoolean(phKeyLowercase, 1); $control->Play(phEventSave,$d1,phDialogSilent); $desc = $ps->MakeDescriptor(); $control = $ps->MakeControlObject(); $control->Play(phEventClose,$desc,phDialogSilent);


But I get the following error message:
Bareword "phKeyLowercase" not allowed while "strict subs" in use at ps +_skript.pl line 46. Execution of thumbcreator.pl aborted due to compilation errors.


If I leave the line $d1->PutBoolean(phKeyLowercase,1);, Photoshop is started, but no Thumbnail is created.

Now I have two questions:
*) Why is no thumbnail created? Where is the mistake in the code?
*) Is there a list of Photoshop-functions I can use with Perl?

thanks, Renee

Replies are listed 'Best First'.
Re: using Photoshop via Perl
by !1 (Hermit) on Dec 27, 2004 at 13:03 UTC

    *) phKeyLowercase does not exist. Perhaps you should be trying phKeyLowerCase?

    *) This should generate a list of all the constants that it exports:

    #!/usr/bin/perl -wl package ap; use Win32::OLE::Const "Adobe Photoshop"; package main; $, = $/; print sort grep defined *{"ap::$_"}{"CODE"}, keys %ap::;

    Update: Hopped over to a machine that actually has AP on it and discovered that your code still doesn't work. Corrected version included in the readmore.

      Thanks for your code. It works fine.
      Great job !1 Excellent reply!!
Re: using Photoshop via Perl
by zentara (Archbishop) on Dec 27, 2004 at 12:37 UTC
    Although I think it is interesting that you are trying to use Photoshop to resize, it is doing it the hard way, unless Photoshop does something "special" that Imager or ImageMagick can't do.

    There are many snippets available for resizing with Imager or ImageMagick, use the Searchbox.


    I'm not really a human, but I play one on earth. flash japh
Re: using Photoshop via Perl
by superfrink (Curate) on Dec 27, 2004 at 20:51 UTC
    I worked on something for a client who had large JPEG images (well 1200x1600 pixels anyway.) The client wanted thumbnail images generated from the large images. He also wanted "drop shadows" added.

    I was using PHP at the time and tried using the GD image libraries . This did work but the client was not happy with the quality of the thumbnails.

    Next I tried the ImageMagik command line tools. Still the client was not happy with the thumbnails.

    In the end he scripted PhotoShop. I'm not sure what is involved but I think it can record button clicks, etc. I can't tell you how to call a PhotoShop script from Perl but it might be useful to look into it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://417531]
Approved by Chady
Front-paged by Anneq
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-19 00:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found