mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 01:16:16 +03:00
Print function in tutorial
This commit is contained in:
parent
b89ae08522
commit
55913cab1b
|
@ -18,7 +18,8 @@ in the :py:mod:`~PIL.Image` module::
|
||||||
If successful, this function returns an :py:class:`~PIL.Image.Image` object.
|
If successful, this function returns an :py:class:`~PIL.Image.Image` object.
|
||||||
You can now use instance attributes to examine the file contents::
|
You can now use instance attributes to examine the file contents::
|
||||||
|
|
||||||
>>> print im.format, im.size, im.mode
|
>>> from __future__ import print_function
|
||||||
|
>>> print(im.format, im.size, im.mode)
|
||||||
PPM (512, 512) RGB
|
PPM (512, 512) RGB
|
||||||
|
|
||||||
The :py:attr:`~PIL.Image.Image.format` attribute identifies the source of an
|
The :py:attr:`~PIL.Image.Image.format` attribute identifies the source of an
|
||||||
|
@ -66,6 +67,7 @@ Convert files to JPEG
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
import os, sys
|
import os, sys
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
@ -76,7 +78,7 @@ Convert files to JPEG
|
||||||
try:
|
try:
|
||||||
Image.open(infile).save(outfile)
|
Image.open(infile).save(outfile)
|
||||||
except IOError:
|
except IOError:
|
||||||
print "cannot convert", infile
|
print("cannot convert", infile)
|
||||||
|
|
||||||
A second argument can be supplied to the :py:meth:`~PIL.Image.Image.save`
|
A second argument can be supplied to the :py:meth:`~PIL.Image.Image.save`
|
||||||
method which explicitly specifies a file format. If you use a non-standard
|
method which explicitly specifies a file format. If you use a non-standard
|
||||||
|
@ -87,6 +89,7 @@ Create JPEG thumbnails
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
import os, sys
|
import os, sys
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
@ -100,7 +103,7 @@ Create JPEG thumbnails
|
||||||
im.thumbnail(size)
|
im.thumbnail(size)
|
||||||
im.save(outfile, "JPEG")
|
im.save(outfile, "JPEG")
|
||||||
except IOError:
|
except IOError:
|
||||||
print "cannot create thumbnail for", infile
|
print("cannot create thumbnail for", infile)
|
||||||
|
|
||||||
|
|
||||||
It is important to note that the library doesn’t decode or load the raster data
|
It is important to note that the library doesn’t decode or load the raster data
|
||||||
|
@ -118,13 +121,14 @@ Identify Image Files
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
import sys
|
import sys
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
for infile in sys.argv[1:]:
|
for infile in sys.argv[1:]:
|
||||||
try:
|
try:
|
||||||
im = Image.open(infile)
|
im = Image.open(infile)
|
||||||
print infile, im.format, "%dx%d" % im.size, im.mode
|
print(infile, im.format, "%dx%d" % im.size, im.mode)
|
||||||
except IOError:
|
except IOError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -518,13 +522,14 @@ Reading in draft mode
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
im = Image.open(file)
|
im = Image.open(file)
|
||||||
print "original =", im.mode, im.size
|
print("original =", im.mode, im.size)
|
||||||
|
|
||||||
im.draft("L", (100, 100))
|
im.draft("L", (100, 100))
|
||||||
print "draft =", im.mode, im.size
|
print("draft =", im.mode, im.size)
|
||||||
|
|
||||||
This prints something like:
|
This prints something like::
|
||||||
|
|
||||||
original = RGB (512, 512)
|
original = RGB (512, 512)
|
||||||
draft = L (128, 128)
|
draft = L (128, 128)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user