mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-04-25 03:23:41 +03:00
Apply black formatting to code examples
This commit is contained in:
parent
bd00cd9214
commit
675c5e1a9c
|
@ -760,7 +760,7 @@ The :py:meth:`~PIL.Image.open` method sets the following attributes:
|
|||
A convenience method, :py:meth:`~PIL.SpiderImagePlugin.SpiderImageFile.convert2byte`,
|
||||
is provided for converting floating point data to byte data (mode ``L``)::
|
||||
|
||||
im = Image.open('image001.spi').convert2byte()
|
||||
im = Image.open("image001.spi").convert2byte()
|
||||
|
||||
Writing files in SPIDER format
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -1201,6 +1201,7 @@ dpi. To load it at another resolution:
|
|||
.. code-block:: python
|
||||
|
||||
from PIL import Image
|
||||
|
||||
with Image.open("drawing.wmf") as im:
|
||||
im.load(dpi=144)
|
||||
|
||||
|
@ -1212,15 +1213,19 @@ To add other read or write support, use
|
|||
from PIL import Image
|
||||
from PIL import WmfImagePlugin
|
||||
|
||||
|
||||
class WmfHandler:
|
||||
def open(self, im):
|
||||
...
|
||||
|
||||
def load(self, im):
|
||||
...
|
||||
return image
|
||||
|
||||
def save(self, im, fp, filename):
|
||||
...
|
||||
|
||||
|
||||
wmf_handler = WmfHandler()
|
||||
|
||||
WmfImagePlugin.register_handler(wmf_handler)
|
||||
|
|
|
@ -176,7 +176,8 @@ Rolling an image
|
|||
xsize, ysize = image.size
|
||||
|
||||
delta = delta % xsize
|
||||
if delta == 0: return image
|
||||
if delta == 0:
|
||||
return image
|
||||
|
||||
part1 = image.crop((0, 0, delta, ysize))
|
||||
part2 = image.crop((delta, 0, xsize, ysize))
|
||||
|
@ -264,6 +265,7 @@ Converting between modes
|
|||
::
|
||||
|
||||
from PIL import Image
|
||||
|
||||
with Image.open("hopper.ppm") as im:
|
||||
im = im.convert("L")
|
||||
|
||||
|
@ -462,6 +464,7 @@ Reading from an open file
|
|||
::
|
||||
|
||||
from PIL import Image
|
||||
|
||||
with open("hopper.ppm", "rb") as fp:
|
||||
im = Image.open(fp)
|
||||
|
||||
|
@ -475,6 +478,7 @@ Reading from binary data
|
|||
|
||||
from PIL import Image
|
||||
import io
|
||||
|
||||
im = Image.open(io.BytesIO(buffer))
|
||||
|
||||
Note that the library rewinds the file (using ``seek(0)``) before reading the
|
||||
|
|
|
@ -87,10 +87,13 @@ true color.
|
|||
|
||||
Image.register_open(SpamImageFile.format, SpamImageFile, _accept)
|
||||
|
||||
Image.register_extensions(SpamImageFile.format, [
|
||||
Image.register_extensions(
|
||||
SpamImageFile.format,
|
||||
[
|
||||
".spam",
|
||||
".spa", # DOS version
|
||||
])
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
The format handler must always set the
|
||||
|
@ -111,6 +114,7 @@ Once the plugin has been imported, it can be used:
|
|||
|
||||
from PIL import Image
|
||||
import SpamImagePlugin
|
||||
|
||||
with Image.open("hopper.spam") as im:
|
||||
pass
|
||||
|
||||
|
|
|
@ -81,6 +81,7 @@ Example: Draw Partial Opacity Text
|
|||
.. code-block:: python
|
||||
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
# get an image
|
||||
with Image.open("Pillow/Tests/images/hopper.png").convert("RGBA") as base:
|
||||
|
||||
|
@ -557,7 +558,9 @@ Methods
|
|||
|
||||
.. code-block:: python
|
||||
|
||||
hello = draw.textlength("HelloW", font) - draw.textlength("W", font) # adjusted for kerning
|
||||
hello = draw.textlength("HelloW", font) - draw.textlength(
|
||||
"W", font
|
||||
) # adjusted for kerning
|
||||
world = draw.textlength("World", font)
|
||||
hello_world = hello + world # adjusted for kerning
|
||||
assert hello_world == draw.textlength("HelloWorld", font) # True
|
||||
|
|
|
@ -17,7 +17,8 @@ changes it.
|
|||
.. code-block:: python
|
||||
|
||||
from PIL import Image
|
||||
with Image.open('hopper.jpg') as im:
|
||||
|
||||
with Image.open("hopper.jpg") as im:
|
||||
px = im.load()
|
||||
print(px[4, 4])
|
||||
px[4, 4] = (0, 0, 0)
|
||||
|
|
|
@ -18,7 +18,8 @@ The following script loads an image, accesses one pixel from it, then changes it
|
|||
.. code-block:: python
|
||||
|
||||
from PIL import Image
|
||||
with Image.open('hopper.jpg') as im:
|
||||
|
||||
with Image.open("hopper.jpg") as im:
|
||||
px = im.load()
|
||||
print(px[4, 4])
|
||||
px[4, 4] = (0, 0, 0)
|
||||
|
|
|
@ -63,6 +63,7 @@ Take your test image, and make a really simple harness.
|
|||
::
|
||||
|
||||
from PIL import Image
|
||||
|
||||
with Image.open(path) as im:
|
||||
im.load()
|
||||
|
||||
|
|
|
@ -14,17 +14,17 @@ The following are all equivalent::
|
|||
import io
|
||||
import pathlib
|
||||
|
||||
with Image.open('test.jpg') as im:
|
||||
with Image.open("test.jpg") as im:
|
||||
...
|
||||
|
||||
with Image.open(pathlib.Path('test.jpg')) as im2:
|
||||
with Image.open(pathlib.Path("test.jpg")) as im2:
|
||||
...
|
||||
|
||||
with open('test.jpg', 'rb') as f:
|
||||
with open("test.jpg", "rb") as f:
|
||||
im3 = Image.open(f)
|
||||
...
|
||||
|
||||
with open('test.jpg', 'rb') as f:
|
||||
with open("test.jpg", "rb") as f:
|
||||
im4 = Image.open(io.BytesIO(f.read()))
|
||||
...
|
||||
|
||||
|
@ -90,11 +90,11 @@ Complications
|
|||
|
||||
* After a file has been closed, operations that require file access will fail::
|
||||
|
||||
with open('test.jpg', 'rb') as f:
|
||||
with open("test.jpg", "rb") as f:
|
||||
im5 = Image.open(f)
|
||||
im5.load() # FAILS, closed file
|
||||
|
||||
with Image.open('test.jpg') as im6:
|
||||
with Image.open("test.jpg") as im6:
|
||||
pass
|
||||
im6.load() # FAILS, closed file
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user