How do I modify my Python image resizer code to do this? -
when resize picture smaller desired, want image not resized...but instead in center, white padding around it.
so, let's have icon that's 50x50. want resize 100x100. if pass function, return me same icon centered, white padding 25 pixels on each side.
of course, i'd work images of width/height, , not square example above.
my current code below.
i don't know why did if height=none: height=width
...i think because worked when did before.
def create_thumbnail(f, width=200, height=none): if height==none: height=width im = image.open(stringio(f)) imagex = int(im.size[0]) imagey = int(im.size[1]) if imagex < width or imagey < height: return none if im.mode not in ('l', 'rgb', 'rgba'): im = im.convert('rgb') im.thumbnail((width, height), image.antialias) thumbnail_file = stringio() im.save(thumbnail_file, 'jpeg') thumbnail_file.seek(0) return thumbnail_file
this code may have many bugs in it, not sure.
one option create blank white image of size want, draw existing image in center.
Comments
Post a Comment