Achieve Results
From the source image, 1000 images are generated in the current working directory under the/IMG directory, from 1*1 to 1000*1000 pixels, respectively.
The effect is as follows:
Directory structure
Implementation examples
#-*-Coding:utf-8-*-import threadingfrom PIL Import imageimage_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: The project requires a reference PIL
library.
Here, we use the resize
function.
As with most script libraries, resize
functions also support chained calls. First by resize((size, size), Image.ANTIALIAS)
specifying the size and quality, where for parameter two:
Parameter values |
Meaning |
Image.nearest |
Low quality |
Image.bilinear |
Bilinear |
Image.bicubic |
Three secondary spline interpolation |
Image.antialias |
Quality |
save("img/png_%d.png" % size)
the method is eventually called to write to the specified location in the specified format.
In addition, multi-threaded concurrency is used, given the large number of linear-intensive operations.
Conclusion
The above is the use of Python batch generation of any size picture of the entire content, I hope to learn from you and use Python can be helpful.