Re: Python scripting with Paint Shop Pro 8.0

Discussion in 'Python' started by Martin Franklin, Jul 21, 2003.

  1. 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, Jul 21, 2003
    #1
    1. Advertising

  2. Martin Franklin

    Marc Wilson Guest

    In comp.lang.python, Martin Franklin
    <> (Martin Franklin) wrote in
    <>::

    |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
    |
    |
    |"""

    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 Wilson

    Cleopatra Consultants Limited - IT Consultants
    2 The Grange, Cricklade Street, Old Town, Swindon SN1 3HG
    Tel: (44/0) 70-500-15051 Fax: (44/0) 870 164-0054
    Mail: Web: http://www.cleopatra.co.uk
    _________________________________________________________________
    Try MailTraq at https://my.mailtraq.com/register.asp?code=cleopatra
     
    Marc Wilson, Jul 21, 2003
    #2
    1. Advertising

  3. Martin Franklin

    Marc Wilson Guest

    In comp.lang.python, Martin Franklin
    <> (Martin Franklin) wrote in
    <>::

    |On Monday 21 July 2003 12:29, Marc Wilson wrote:
    |> In comp.lang.python, Martin Franklin
    |> <> (Martin Franklin) wrote in
    |>
    |> <>::
    |> |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
    |> |
    |> |
    |> |"""
    |>
    |> 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.

    Groovy. I may become a Python convert. *sigh* I've not finished learning
    perl yet, and now I've got a new shiny toy. :)

    OK, I'll try installing the "proper" Python and see what's what.
    --
    Marc Wilson

    Cleopatra Consultants Limited - IT Consultants
    2 The Grange, Cricklade Street, Old Town, Swindon SN1 3HG
    Tel: (44/0) 70-500-15051 Fax: (44/0) 870 164-0054
    Mail: Web: http://www.cleopatra.co.uk
    _________________________________________________________________
    Try MailTraq at https://my.mailtraq.com/register.asp?code=cleopatra
     
    Marc Wilson, Jul 21, 2003
    #3
  4. Martin Franklin

    Marc Wilson Guest

    In comp.lang.python, (John J. Lee) (John J. Lee) wrote in
    <>::

    |Marc Wilson <> 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>.

    Perhaps. It might take a whole day if the phone keeps ringing :)
    |
    |http://effbot.org/zone/pil-imageenhance.htm
    |http://effbot.org/zone/pil-imagefilter.htm
    |
    |
    |And I'm sure that afternoon will pay off again.

    Prolly.

    |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>.

    Win2K, so not the worst platform, nor the best, I imagine.
    --
    Marc Wilson

    Cleopatra Consultants Limited - IT Consultants
    2 The Grange, Cricklade Street, Old Town, Swindon SN1 3HG
    Tel: (44/0) 70-500-15051 Fax: (44/0) 870 164-0054
    Mail: Web: http://www.cleopatra.co.uk
    _________________________________________________________________
    Try MailTraq at https://my.mailtraq.com/register.asp?code=cleopatra
     
    Marc Wilson, Jul 21, 2003
    #4
  5. Martin Franklin

    Peter Hansen Guest

    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. :)
     
    Peter Hansen, Jul 21, 2003
    #5
  6. Martin Franklin

    Marc Wilson Guest

    In comp.lang.python, Peter Hansen <> (Peter Hansen) wrote
    in <>::

    |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. :)

    I'm not here to participate in any religious wars. :)
    --
    Marc Wilson

    Cleopatra Consultants Limited - IT Consultants
    2 The Grange, Cricklade Street, Old Town, Swindon SN1 3HG
    Tel: (44/0) 70-500-15051 Fax: (44/0) 870 164-0054
    Mail: Web: http://www.cleopatra.co.uk
    _________________________________________________________________
    Try MailTraq at https://my.mailtraq.com/register.asp?code=cleopatra
     
    Marc Wilson, Jul 21, 2003
    #6
  7. Martin Franklin

    Peter Hansen Guest

    Marc Wilson wrote:
    >
    > In comp.lang.python, Peter Hansen <> (Peter Hansen) wrote
    > in <>::
    >
    > |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. :)
    >
    > I'm not here to participate in any religious wars. :)


    Sorry, I must have misinterpreted your use of the word "convert" then. ;-)
     
    Peter Hansen, Jul 21, 2003
    #7
  8. Martin Franklin

    Aahz Guest

    In article <>,
    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. :)


    <smirk>
    --
    Aahz () <*> http://www.pythoncraft.com/

    This is Python. We don't care much about theory, except where it intersects
    with useful practice. --Aahz
     
    Aahz, Jul 23, 2003
    #8
  9. Martin Franklin

    Marc Wilson Guest

    In comp.lang.python, Martin Franklin
    <> (Martin Franklin) wrote in
    <>::

    |On Monday 21 July 2003 12:29, Marc Wilson wrote:
    |> In comp.lang.python, Martin Franklin
    |> <> (Martin Franklin) wrote in
    |
    |> 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.

    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 Wilson

    Cleopatra Consultants Limited - IT Consultants
    2 The Grange, Cricklade Street, Old Town, Swindon SN1 3HG
    Tel: (44/0) 70-500-15051 Fax: (44/0) 870 164-0054
    Mail: Web: http://www.cleopatra.co.uk
    _________________________________________________________________
    Try MailTraq at https://my.mailtraq.com/register.asp?code=cleopatra
     
    Marc Wilson, Jul 24, 2003
    #9
  10. Martin Franklin

    Duncan Booth Guest

    Marc Wilson <> wrote in
    news::

    > 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()


    --
    Duncan Booth
    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, Jul 24, 2003
    #10
  11. Martin Franklin

    Marc Wilson Guest

    In comp.lang.python, Martin Franklin
    <> (Martin Franklin) wrote in
    <>::

    |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))
    |
    That would be the preferred option: we already have a suitable JPEG for the
    system we use now.

    Thanks- you guys are so helpful to a clue-impaired newbie.
    --
    Marc Wilson

    Cleopatra Consultants Limited - IT Consultants
    2 The Grange, Cricklade Street, Old Town, Swindon SN1 3HG
    Tel: (44/0) 70-500-15051 Fax: (44/0) 870 164-0054
    Mail: Web: http://www.cleopatra.co.uk
    _________________________________________________________________
    Try MailTraq at https://my.mailtraq.com/register.asp?code=cleopatra
     
    Marc Wilson, Jul 24, 2003
    #11
  12. Martin Franklin

    Marc Wilson Guest

    In comp.lang.python, Duncan Booth <> (Duncan Booth)
    wrote in <Xns93C2B04C1DD91duncanrcpcouk@127.0.0.1>::

    |Marc Wilson <> wrote in
    |news::
    |
    |> 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()

    Yep- that works a treat. Incidentally, why do I need to remove the text
    area before overwriting it? Or am I missing the point?
    --
    Marc Wilson

    Cleopatra Consultants Limited - IT Consultants
    2 The Grange, Cricklade Street, Old Town, Swindon SN1 3HG
    Tel: (44/0) 70-500-15051 Fax: (44/0) 870 164-0054
    Mail: Web: http://www.cleopatra.co.uk
    _________________________________________________________________
    Try MailTraq at https://my.mailtraq.com/register.asp?code=cleopatra
     
    Marc Wilson, Jul 24, 2003
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    4,674
    Brendan Guild
    Oct 23, 2005
  2. Aahz
    Replies:
    5
    Views:
    808
    Duncan Booth
    Jul 22, 2003
  3. Greg Brunet
    Replies:
    4
    Views:
    1,129
    Kevin Dahlhausen
    Jul 23, 2003
  4. Ron Stephens
    Replies:
    23
    Views:
    3,020
    Ron Stephens
    Apr 12, 2004
  5. Wayne Erfling
    Replies:
    0
    Views:
    364
    Wayne Erfling
    Nov 18, 2006
Loading...

Share This Page