[Pythonmac-SIG] py2app = newbie path confusion
corporate user
layne.bilyeu at robbstucky.net
Wed Apr 19 03:27:38 CEST 2006
On Apr 18, 2006, at 8:44 PM, Bob Ippolito wrote:
>
> Print the paths and make sure they are what you expect them to be.
> Without seeing the script there's little else I can tell you.
>
Thanks, didn't know if stupid newbie noise is acceptable here.
Very simple beginner script. Not sure why it doesn't write files
after py2appletizing.
Seems to work just fine from the command line. What am I missing?
----------------------------
#!/usr/bin/env pythonw
"""
imageSizer - drag & drop image files onto this applet:
Will create 2 Jpg files, names appended with a letter
A - 432x432 pixels
B - 150x150 pixels
and will add whitespace to make images Square.
"""
import os, sys
import Image, ImageFilter
indent = " "
BICUBIC = 3 ###Image module broke? so define it's constant here
def main():
for infile in sys.argv[1:]:
try:
im = Image.open(infile)
namebase = os.path.splitext(os.path.basename(infile)) [0]
print "\n" + namebase
##strip B.S. from end of name (assume SKU number 15 digits)
##a regular expression would be better,
##if I could figure out the random logic users name things with
namebase = namebase[0:15]
width, height = im.size
print indent + str(im.format) + indent + "width %d, height %d" %
(width, height)
if width != height:
print indent + "Alert! Image is not square!"
im = adjustsize(im)
makeAsize(im, namebase)
makeBsize(im, namebase)
except IOError, errMsg:
print "Caught Error\n" + str(errMsg)
def adjustsize(daimage):
width, height = daimage.size
if width > height:
print indent + "--wide image, space needed on top & bottom"
spacer = (width - height)/2
print indent + " creating new image %d x %d" % (width, width)
newimage = Image.new("RGB", (width, width), (255, 255, 255))
newimage.paste( daimage, (0, spacer) )
else:
print indent + "--tall image, space needed on sides"
spacer = (height - width)/2
print indent + " creating new image %d x %d" % (height, height)
newimage = Image.new("RGB", (height, height), (255, 255, 255))
newimage.paste( daimage, (spacer, 0) )
return newimage
def makeAsize(image, basename):
outname = basename + "A" + ".jpg"
print indent + "--creating " + outname
out = image.resize( (432,432), BICUBIC)
out.save(outname, "JPEG")
def makeBsize(image, basename):
outname = basename + "B" + ".jpg"
print indent + "--creating " + outname
out = image.resize( (150,150), BICUBIC)
out.save(outname, "JPEG")
if __name__ == '__main__':
main()
More information about the Pythonmac-SIG
mailing list