imagesequence The module includes a wrapper class that allows users to iterate through each frame of an image in a sequence of graphics.
function of the imagesequence Module
1. Iterator
Definition:imagesequence.iterator (image)? Iterator Instance
Meaning: Create an iterator instance that allows the user to iterate through all the frame images in the sequence.
Examples: see below for examples.
Second, the method of Imagesequence module
1. Operator
Definition: Operator []
Meaning: The user invokes the operator, starting from 0 .
When there is no other frame image. This iterator will produce a indexerror exception.
Examples:
From PIL import image, Imagesequenceim = Image.open ("d:\\code\\python\\test\\img\\test01.gif") index = 1for frame in Image Sequence.iterator (IM): print "Image:index%d, mode%s, size%s"% (index, Frame.mode, frame.size) Frame.save ("fr Ame%d.png "% index" index = index + 1iter = Imagesequence.iterator (IM) print "Image 10:mode%s, size%s"% (iter[10].m Ode, Iter[10].size) Iter[10].show ()
The image is test01.gif as multiple dynamic images.
An iterator to the im of the image object is obtained through the function imagesequence.iterator (IM) , and each picture is taken out of one sheet. Their patterns and dimensions are printed. The corresponding image in the iterator is obtained later by the operator [] . iter[10] corresponds to the tenth image.
The program outputs such as the following:
Image:index 1, Mode P, size (450, 450)
Image:index 2, Mode P, size (450, 450)
Image:index 3, Mode P, size (450, 450)
Image:index 4, Mode P, size (450, 450)
Image:index 5, Mode P, size (450, 450)
Image:index 6, Mode P, size (450, 450)
Image:index 7, Mode P, size (450, 450)
Image:index 8, Mode P, size (450, 450)
Image:index 9, Mode P, size (450, 450)
Image:index, Mode P, size (450, 450)
Image:index, Mode P, size (450, 450)
Image:index, Mode P, size (450, 450)
Image:index, Mode P, size (450, 450)
Image:index, Mode P, size (450, 450)
Image:index, Mode P, size (450, 450)
Image:index, Mode P, size (450, 450)
Image:index, Mode P, size (450, 450)
Image:index, Mode P, size (450, 450)
Image:index, Mode P, size (450, 450)
Image:index, Mode P, size (450, 450)
Image:index, Mode P, size (450, 450)
Image:index, Mode P, size (450, 450)
Image:index, Mode P, size (450, 450)
Image10:mode P, size (450, 450)
Image Test01.gif such as the following:
The second image is:
Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center ">
The 20th image is:
Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center ">
The tenth image obtained by the operator [] is followed by the following example:
Imagesequence module Introduction to Python image processing library pil