To make it easier to create pictures for the Picky
Picky Game, I have added code to automatically convert
Microsoft Windows Bitmap (
.bmp) files into
This is straightforward because I already was using PIL to check the dimensions of the images. Converting to PNG (if the format is one PIL knows) is pretty simple:
permittedTypes = ['image/png', 'image/jpeg', 'image/pjpeg', 'image/gif'] ... if not imt in permittedTypes: buf = StringIO.StringIO() im.save(buf, 'PNG') data = buf.getvalue() logger.log(slog.WARNING, 'Converted your image from %s to image/png' % imt, 'This may have lead to a slight loss of image quality.') imt = 'image/png' buf.close()
The above goes in the sequence of checks on uploaded images (after the check for width × height, but before the check for number of bytes). I think I spent longer creating a BMP image to test it on than I did writing the new code!
The advantage of BMP support is that, if you have Microsoft Windows, then you definitely have Microsoft Paint installed. So long as you know about Start menu → Programs → Accessories → Paint, and the Image → Attributes menu item, you can create panels for Picky Picky Game.