I need to convert PNG images to JPG..can python help

Steve Lamb grey at despair.rpglink.com
Wed Apr 18 14:41:01 EDT 2001


On Wed, 18 Apr 2001 14:38:34 -0300, Chris Richard Adams
<chrisa at ASPATECH.COM.BR> wrote:
>I've been using ImageMagick on Linux to convert images from PNG to JPG,
>but now need to include that code in a python script.  My options are to
>somehow figure out how do call imagemagick's 'convert' from a python
>script or to use a library/module within python.  Anyone have an
>tips/advice?

    From a small script I wrote to automate the process of taking Asheron's
Call screen shots and tossing them up on a web page for my allegiance to
enjoy:

    def cvt(self, ext):
        files = os.listdir('.')
        for x in range(len(files)):
            oldfile = files[x]
            newfile = '%s.%s' % (oldfile[:-4], ext)
            os.system('%s %s %s' % (self.convert, oldfile, newfile))


    Oh, and don't ask me why I did x in range(len(files)) instead of just x in
files, I just did, it works, haven't changed it yet.  :)

    Anyway, self.convert is the path to convert and it takes the extension to
convert the graphics to.

-- 
         Steve C. Lamb         | I'm your priest, I'm your shrink, I'm your
         ICQ: 5107343          | main connection to the switchboard of souls.
-------------------------------+---------------------------------------------



More information about the Python-list mailing list