Achieve the effect
Use the source image to generate 1000 images ranging from 1*1 to 1000*1000 pixels in the /img directory of the current working directory.
The effect is as follows:
Directory structure
Implementation example
# -*- coding: utf-8 -*- import threading from PIL import Image image_size = range(1, 1001) def start(): for size in image_size: t = threading.Thread(target=create_image, args=(size,)) t.start() def create_image(size): pri_image = Image.open("origin.png") pri_image.resize((size, size), Image.ANTIALIAS).save("img/png_%d.png" % size) if __name__ == "__main__": start()
Note: This project needs to reference the PIL
library.
Here, we use the resize
function.
Like most script libraries, the resize
function also supports chained calls. First specify the size and quality through resize((size, size), Image.ANTIALIAS)
, where for parameter two:
parameter Value | ##Meaning |
Low quality | |
Bilinear | |
cubic spline interpolation | |
High Quality |
save("img/png_%d.png" % size) method , writes to the specified location in the specified format.
Conclusion
The above is the entire content of using Python to batch generate images of any size. I hope it will be helpful for everyone to learn and use Python. . For more articles related to Python batch generation of images of any size, please pay attention to the PHP Chinese website!