Implementation effect
From the source picture, in the current working directory in the/IMG directory to generate 1000 pieces, from 1*1 to 1000*1000 pixels of the picture.
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 requires a reference PIL
library.
Here, we use resize
functions.
Like most script libraries, resize
functions also support chained calls. First by resize((size, size), Image.ANTIALIAS)
specifying the size and quality, which for parameter two:
Parameter values |
Meaning |
Image.nearest |
Low quality |
Image.bilinear |
Bilinear |
Image.bicubic |
Three cubic spline interpolation |
Image.antialias |
Quality |
The final calling save("img/png_%d.png" % size)
method to write to the specified location in the specified format.
In addition, multithreading concurrency is used in view of the large number of linear-intensive operations.
Conclusion
The above is the use of Python batch production of any size pictures of the entire content, I hope to learn and use Python can help.