Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Python scripting with Paint Shop Pro 8.0

353 views
Skip to first unread message

Aahz

unread,
Jul 20, 2003, 9:44:24 AM7/20/03
to
In article <kl3lhvgh5iillo5g9...@4ax.com>,
Marc Wilson <ma...@cleopatra.co.uk> wrote:
>
>I'm a complete Python newbie, though I know at least one regular in
>here. :)

Hi, Marc!

>What I'm trying to determine is: can I run these scripts from a
>command-line invocation? I want to use the scripts to automatically
>convert files as they arrive, uploaded onto a website, not
>interactively.

Don't know PSP, but normally this kind of facility would be made
available through an importable module. If that's not an option, check
to see whether PSP allows specifying a script on the command line;
presumably their embedded Python permits you to exit PSP.
--
Aahz (aa...@pythoncraft.com) <*> http://www.pythoncraft.com/

This is Python. We don't care much about theory, except where it intersects
with useful practice. --Aahz

John J. Lee

unread,
Jul 20, 2003, 7:19:44 PM7/20/03
to
Marc Wilson <ma...@cleopatra.co.uk> writes:
[...]
> There's no obvious way to specify this on the command line- in fact the
> phrase "command line" doesn't seem to occur in the help.
>
> The scripts all start with "from JascApp import *" - does this suggest that
> the scripts are callable from "plain" python? I want a "quiet" execution

Yes. Do a find for 'JascApp.pyd'. Or just for '*.pyd'.


> with no Windows interaction. I assume that there is a library called
> JascApp.<something> and the path would need to include that?

Yes, <something> == 'pyd' usually. But you never know the ways people
(and especially large companies) like to mess about with conventional
ways of doing things.

The way module search paths are handled is generally less easy to
predict. Even in the normal case, I can't remember how .pyd's are
found, if I ever knew. Presumably Python is bundled with the
application, in some form? In which case, it may not be trivial to
import the module. Probably not hard once you know the answer, though
<wink>.


John

Martin Franklin

unread,
Jul 21, 2003, 4:01:24 AM7/21/03
to
On Sunday 20 July 2003 13:48, Marc Wilson wrote:
> Hi,

>
> I'm a complete Python newbie, though I know at least one regular in here.
> :)
>
> I've just got Paint Shop Pro 8.0, and the functionality of the old
> ImageRobot add-on has been replaced with the new Python Scripting.
>
> So far, OK.

>
> What I'm trying to determine is: can I run these scripts from a
> command-line invocation? I want to use the scripts to automatically
> convert files as they arrive, uploaded onto a website, not interactively.
>
> Has anyone played with this?
> --
> Marc Wilson
>

Marc,

This is not an answer to your question... but if you just want to convert an
image file into another format then upload it to a server you could use a
pure python solution (well pure python + PIL)

PIL is here:-

http://www.pythonware.com/products/pil/

In fact a quick browse through the handbook and I found this:-

http://www.pythonware.com/library/pil/handbook/pilconvert.htm

and I quote:-

"""
Convert an image from one format to another. The output format is determined
by the target extension, unless explicitly specified with the -c option.

$ pilconvert lena.tif lena.png
$ pilconvert -c JPEG lena.tif lena.tmp


"""

To upload the image to a server you could use the ftplib module...


Regards
Martin


Martin Franklin

unread,
Jul 21, 2003, 8:23:06 AM7/21/03
to
On Monday 21 July 2003 12:29, Marc Wilson wrote:
> In comp.lang.python, Martin Franklin
> <mfran...@gatwick.westerngeco.slb.com> (Martin Franklin) wrote in
>
> <mailman.105877515...@python.org>::
> It's a start- actually, we want to convert the file to JPEG (if not
> already), sharpen it, fix the size and also derive a thumbnail from it.
>
> We used something called Image Robot, a helper application from JASC. Now
> that they have integrated this functionality into PSP, they no longer
> support IR, and we're having odd problems with it, so we're looking to see
> if we can do the same thing with a supported level.
>
> While I'm sure Python is a lovely language, the choice is due to PSP using
> the scripting engine: if I have to write something from scratch (or even
> from bits'n'bobs), I'll use a language I already know.

>
> |To upload the image to a server you could use the ftplib module...
>
> Already got it on the server- the customers upload the files using a web
> form.

Marc,

Point taken... I just can't resist showing you how easy it is in Python.....

# PIL IMPORTS
import Image, ImageEnhance

im = Image.open("gnome-mixer.jpg")

enhancer = ImageEnhance.Sharpness(im)
eim = enhancer.enhance(2.0)
eim.save("gnome-mixer-sharp.jpg", "JPEG")

eim.thumbnail((10, 10))
eim.save("gnome-mixer-thumb.jpg", "JPEG")


And this is the first time I've used PIL.


Cheers,
Martin.


John J. Lee

unread,
Jul 21, 2003, 9:45:17 AM7/21/03
to
Marc Wilson <ma...@cleopatra.co.uk> writes:
[...]
> The documentation is, er, sketchy. The manual refers you to a non-existant
> folder on the CD, and the Python content is referred to as the "Python
> Scripting Engine", which suggests it may not be a full implementation. If I
> have to install Python separately, so be it. I'll look for the .pyd file
> and see if there a suspiciously-named executable there as well.

The fact that it's embedded doesn't necessarily mean that you can't
import it from outside the running application, but it may well not be
possible. Worth a try, though.

As I said in an email, don't forget COM -- maybe one of those .py
files you have is just a wrapper around a COM automation interface.
The "Python for Windows extensions" (aka win32all) is what you need
for most COM stuff.


John

Duncan Booth

unread,
Jul 21, 2003, 9:55:34 AM7/21/03
to
Marc Wilson <ma...@cleopatra.co.uk> wrote in
news:kl3lhvgh5iillo5g9...@4ax.com:

> I'm a complete Python newbie, though I know at least one regular in
> here. :)
>
> I've just got Paint Shop Pro 8.0, and the functionality of the old
> ImageRobot add-on has been replaced with the new Python Scripting.
>
> So far, OK.
>
> What I'm trying to determine is: can I run these scripts from a
> command-line invocation? I want to use the scripts to automatically
> convert files as they arrive, uploaded onto a website, not
> interactively.

Have you tried running a script from the commandline?

>
> Has anyone played with this?

I just downloaded the PSP8 evaluation. It installs with a bunch of sample
scripts. These sample scripts all have a file extension .PspScript, and the
file association set up by the installer associates .PspScript with the
command: "...\Paint Shop Pro.exe" "/Script" "%1"

Unfortunately whenever I start Paintshop pro it gives me a popup window
telling me its an evaluation copy and requiring me to confirm the window
before it proceeds. When started with a script that uses a dialog there
appears to be a deadlock as the script cannot proceed with this window
displayed, and the window won't accept any input. It works alright though
for scripts that don't try to do anything interactive, and I would guess
that a properly registered copy of the program would run scripts with
dialogs correctly, but you are probably in a better situation to determine
that than anyone on this newsgroup.

--
Duncan Booth dun...@rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?

Duncan Booth

unread,
Jul 21, 2003, 10:00:26 AM7/21/03
to
Marc Wilson <ma...@cleopatra.co.uk> wrote in
news:bpnmhvg7m3sf3rjph...@4ax.com:

> The documentation is, er, sketchy. The manual refers you to a
> non-existant folder on the CD, and the Python content is referred to
> as the "Python Scripting Engine", which suggests it may not be a full
> implementation. If I have to install Python separately, so be it.
> I'll look for the .pyd file and see if there a suspiciously-named
> executable there as well.
>

The documentation is available as a separate download (for those people who
didn't get their copy on CD, such as the evaluation copy). 4798 files, but
having looked at them I wouldn't say they were the best documentation ever.

John J. Lee

unread,
Jul 21, 2003, 10:06:59 AM7/21/03
to
Marc Wilson <ma...@cleopatra.co.uk> writes:
[...]
> While I'm sure Python is a lovely language, the choice is due to PSP using
> the scripting engine: if I have to write something from scratch (or even
> from bits'n'bobs), I'll use a language I already know.
[...]

Very wise. It would take you a whole afternoon to learn Python well
enough to do what you want with PIL <0.2 wink>.

http://effbot.org/zone/pil-imageenhance.htm
http://effbot.org/zone/pil-imagefilter.htm


And I'm sure that afternoon will pay off again.

OK, and another day to get out of the mess your OS (whichever one you
use) will try to get you into with naming conventions, filesystem
paths and other plumbing <0.8 wink>.


John

Rune Braathen

unread,
Jul 21, 2003, 12:34:10 PM7/21/03
to
Marc Wilson wrote:
> It's a start- actually, we want to convert the file to JPEG (if not
> already), sharpen it, fix the size and also derive a thumbnail from it.

I don't know whether that is doable with the python scripting in
PaintShop Pro as I haven't got round to upgrading yet, but I do know
that Python+PIL can do that in very few lines of work. With some
tweaking, you can use py2exe to make your script into an executable,
thereby removing the need for every user to install python.

( ... )

> While I'm sure Python is a lovely language, the choice is due to PSP using
> the scripting engine: if I have to write something from scratch (or even
> from bits'n'bobs), I'll use a language I already know.

That's a very sound argument. However, if you are planning on doing any
image processing in the future, you will never regret the time spent
learning Python and PIL. In fact, it is a fairly good possibility that
you would look back and wonder how you ever survived without it.

--
runeb

Peter Hansen

unread,
Jul 21, 2003, 2:27:10 PM7/21/03
to
Marc Wilson wrote:
>
> Groovy. I may become a Python convert. *sigh* I've not finished learning
> perl yet, and now I've got a new shiny toy. :)

Excellent! You have much less to _un_learn then. :-)

Greg Brunet

unread,
Jul 21, 2003, 3:06:42 PM7/21/03
to
Hi Marc:

"Marc Wilson" <ma...@cleopatra.co.uk> wrote in message
news:kl3lhvgh5iillo5g9...@4ax.com...


> I've just got Paint Shop Pro 8.0, and the functionality of the old
> ImageRobot add-on has been replaced with the new Python Scripting.

Thanks for mentioning PSP 8's support of Python. I have an older copy
that I haven't updated for a while, and this scripting capability is an
update worthwhile making!

> What I'm trying to determine is: can I run these scripts from a
command-line
> invocation? I want to use the scripts to automatically convert files
as
> they arrive, uploaded onto a website, not interactively.

I just DL'd an eval copy also, and a couple of thoughts.
1) Duncan's already pointed out the file association, so it looks like
that's an easy way to ensure that the Python script is handled properly
by PSP.

2) Python was installed there for me. You should see "python22.dll" in
your [C:\Program Files\Jasc Software Inc\Paint Shop Pro 8] (or
appropriate) directory. There shold also be a [\Python Libraries]
subdirectory with other required files.

3) Interestingly, I can't find any sign of a JascApp.* file anywhere. I
would expect to see a PYC or PYD given the Import command, but being a
relative newbie myself, don't have a good understanding of how this
could be. But, hey - it seems to work, so I won't complain.

4) I would expect that for btach processing you would also pass the file
to process at the command shell, but they do seem to offer some extra
help for batch processing (the "Processing all the files in a directory"
section on page 26 of the script.pdf manual (available at their website
if you've only got all the HTML documentation from the CD) I agree that
the Docs could be a bit more helpful!

5) Of course the messages showing off PIL have opened my eyes to how
easy it is to use that - and Python is LOTS easier than Perl IMHO.

--
Greg

Peter Hansen

unread,
Jul 21, 2003, 4:45:58 PM7/21/03
to
Marc Wilson wrote:
>
> In comp.lang.python, Peter Hansen <pe...@engcorp.com> (Peter Hansen) wrote
> in <3F1C307E...@engcorp.com>::
> I'm not here to participate in any religious wars. :)

Sorry, I must have misinterpreted your use of the word "convert" then. ;-)

David Bolen

unread,
Jul 21, 2003, 5:06:18 PM7/21/03
to
"Greg Brunet" <gregb...@NOSPAMsempersoft.com> writes:

> 3) Interestingly, I can't find any sign of a JascApp.* file anywhere. I
> would expect to see a PYC or PYD given the Import command, but being a
> relative newbie myself, don't have a good understanding of how this
> could be. But, hey - it seems to work, so I won't complain.

This would work if they "embedded" Python rather than "extending" it.
Using Python as an embedded scripting engine, the embedding
application (probably the main PSP executable) can define whatever
modules it wants as built-in modules prior to executing Python code.
The "modules" actually exist right in the executable that is starting
the Python interpreter.

If true, then it would make it less likely you could use that
functionality from an externally initiated Python script, since that
script wouldn't have started from the right environment containing
those built-in modules.

-- David

Duncan Booth

unread,
Jul 22, 2003, 4:14:00 AM7/22/03
to
Marc Wilson <ma...@cleopatra.co.uk> wrote in
news:t25ohv824kde3dh6h...@4ax.com:

>|The documentation is available as a separate download (for those
>|people who didn't get their copy on CD, such as the evaluation copy).
>|4798 files, but having looked at them I wouldn't say they were the
>|best documentation ever.
>

> I do have a CD, but the files aren't on it. Perhaps it's a duff CD.

See the downloads area at
http://www.jasc.com/products/paintshoppro/components.asp
for Scripting for Script Authors and Paint Shop Pro 8 Scripting API
downloads.

Gerhard Häring

unread,
Jul 22, 2003, 1:09:01 PM7/22/03
to
Marc Wilson wrote:
> [...] One thing I've not found in the reference (perhaps I'm looking in the wrong
> place): how do I capture command-line parameters? [...]

sys.argv

For fancier options, check out optparse (new in 2.3) or getopt.

-- Gerhard

Aahz

unread,
Jul 22, 2003, 11:58:16 PM7/22/03
to
In article <h65ohvs749mp0gctg...@4ax.com>,

Marc Wilson <ma...@cleopatra.co.uk> wrote:
>
>Groovy. I may become a Python convert. *sigh* I've not finished learning
>perl yet, and now I've got a new shiny toy. :)

<smirk>

Kevin Dahlhausen

unread,
Jul 23, 2003, 9:46:41 AM7/23/03
to
"Greg Brunet" <gregb...@NOSPAMsempersoft.com> wrote in message news:<vhoefdf...@corp.supernews.com>...

> Thanks for mentioning PSP 8's support of Python. I have an older copy
> that I haven't updated for a while, and this scripting capability is an
> update worthwhile making!
>

Greg,

If you do upgrade, please let them know that the python scripting was
a major factor in your decision to do so.

Martin Franklin

unread,
Jul 24, 2003, 10:52:51 AM7/24/03
to
On Thursday 24 July 2003 3:14 pm, Marc Wilson wrote:
> In comp.lang.python, Martin Franklin
> <mfran...@gatwick.westerngeco.slb.com> (Martin Franklin) wrote in
>
> <mailman.1058790515...@python.org>::

> |On Monday 21 July 2003 12:29, Marc Wilson wrote:
> |> In comp.lang.python, Martin Franklin
> |> <mfran...@gatwick.westerngeco.slb.com> (Martin Franklin) wrote in
> |>

<snip>

> |
> |# PIL IMPORTS
> |import Image, ImageEnhance
> |
> |im = Image.open("gnome-mixer.jpg")
> |
> |enhancer = ImageEnhance.Sharpness(im)
> |eim = enhancer.enhance(2.0)
> |eim.save("gnome-mixer-sharp.jpg", "JPEG")
> |
> |eim.thumbnail((10, 10))
> |eim.save("gnome-mixer-thumb.jpg", "JPEG")
> |
> |
> |And this is the first time I've used PIL.
>

> Wow. I've now knocked up a script that can be called in "batch" mode to
> convert and sharpen the image, and produce a thumbnail from it.
>
> All I need to do now is resize the image (to a fixed width) and we're
> laughing. I'll press on.
>
> Oh, and- is there a way to overwrite text onto an image? The site is a
> house-sales site, and we want to overwrite "SOLD" across the thumbnail once
> a property is sold. It looks like I can do this with the ImageDraw module,
> but I can't see how to replicate what we do now with Image Robot, which is
> to write "SOLD" across the image diagonally (using the Add Watermark
> feature). Any ideas?
>
>

Marc,

Looks like there could be (at least) two ways to do it...
The ImageDraw class allows you to draw onto an existing image like so:-


im = Image.open("gnome-mixer.jpg")

draw = ImageDraw.Draw(im)
draw.text((5, 5), "SOLD", fill="black")


I have not investigated how (and if) you can rotate the text - I know you can
change it's font etc...

The second way would be to paste a SOLD image onto the original image

im = Image.open("gnome-mixer.jpg")

im.paste(Image.open("sold.jpg"), (5, 5))


HTH
Martin


Duncan Booth

unread,
Jul 24, 2003, 12:21:43 PM7/24/03
to
Marc Wilson <ma...@cleopatra.co.uk> wrote in
news:bupvhv4sgqtqlhlpv...@4ax.com:

> Oh, and- is there a way to overwrite text onto an image? The site is
> a house-sales site, and we want to overwrite "SOLD" across the
> thumbnail once a property is sold. It looks like I can do this with
> the ImageDraw module, but I can't see how to replicate what we do now
> with Image Robot, which is to write "SOLD" across the image diagonally
> (using the Add Watermark feature). Any ideas?

How about this:

from PIL import Image, ImageFont, ImageDraw, ImageChops

im = Image.open("test.jpg")
im.thumbnail((128, 128), Image.ANTIALIAS)

font = ImageFont.truetype("arial.ttf", 30)

def AddOverlay(im, origin, text, angle=-45):
# Create an overlay with white text and subtract it from the image.
# This effectively blacks out the area to be overlaid.
overlay = Image.new(im.mode, im.size)
draw = ImageDraw.Draw(overlay)
draw.text(origin, text, (255, 255, 255), font=font)
overlay = overlay.rotate(angle)
stamped = ImageChops.subtract(im, overlay, 1, 0)


# Now create a red overlay and add it to the subtracted image
overlay = Image.new(im.mode, im.size)
draw = ImageDraw.Draw(overlay)
draw.text(origin, text, (255, 0, 0), font=font)
overlay = overlay.rotate(angle)
stamped = ImageChops.add(stamped, overlay, 1, 0)
return stamped

stamped = AddOverlay(im, (10, 50), "SOLD!")
stamped.show()

0 new messages