[CLUG-chat] Intro into programming.
brendon at gleesonprop.co.za
Thu Aug 3 12:35:55 SAST 2006
Neil Blakey-Milner wrote:
> #!/usr/bin/env python
> import Image, ftplib, sys # import needed modules
> fn, wfn = sys.argv[1:3] # get command line arguments
> im = Image.open(fn) # load original image
> wim = Image.open(wfn) # load watermark file
> mim = wim.convert("L") # convert to mask
> im.paste(wim, None, mim) # apply watermark to image
> im.save('out2.jpg', None) # save to temporary file (could use tempfile module)
> site = ftplib.FTP('localhost') # connect to FTP site
> site.storbinary("PUT out2.jpg", file('out2.jpg')) # store file
> Sorry, exactly 10 lines if you include the shebang path. This will
> raise an exception and quit as soon as the first error occurs. This
> exception can be caught. This code can be put in a function, and will
> not leak resources. On caught exceptions, no spurious comments will be
> sent to the screen/browser/log.
> To do as much of the same as a PHP4 "script":
Case and point. ;-) a good illustration!
More information about the clug-chat