I don't know if you have ever encountered this problem. we need 1000 images, ranging from 1x1 to 1000x1000 pixels. After searching, it was found that Python was easy to implement. I decided to use Python to implement this function. I would like to share it with you. For more information, see. Effect
The source image is used to generate 1000 images in the/img Directory of the current working directory, ranging from 1*1 to 1000*1000 pixels.
The effect is as follows:
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 must reference the PIL Library.
Here, we use the resize function.
Like most script libraries, the resize function also supports chained calling. First, use resize (size, size), Image. ANTIALIAS) to specify the size and quality. for parameter 2:
Finally, the save ("img/png_mongod.png" % size) method is called to write data to the specified location in a specified format.
In addition, considering a large number of linear-intensive operations, multithreading concurrency is used.
Conclusion
The above is the use of Python to generate all the content of images of any size in batches, hope to help you learn and use Python.
For more articles about batch generation of images of any size using Python, refer to PHP Chinese network!