How do I create a new image with a black background and paste another image on top of it?
What I am looking to do is turn some 128×128 transparent icons into 75×75 black background icons.
Doesnt work …
import Image
theFile = "/home/xxxxxx/Pictures/xxxxxx_128.png"
img = Image.open(theFile)
newImage = Image.new(img.mode, img.size, "black")
newImage.paste(img)
newImage.resize((75,75))
newImage.save("out.png")
print "Done"
Thanks!
The
resizemethod returns a new image object, rather than changing the existing one. Also, you should resize the image before pasting it. The following works for me:I found an example of this
split+masktechnique from this blog post.Example input:
Output: