From ef93860cb0bd1d45a0d2a8491eb2712e23e1401e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Thu, 2 Feb 2023 15:13:05 +0100 Subject: [PATCH] Image --- README.md | 44 ++++++++++++++++++++++---------------------- index.html | 44 ++++++++++++++++++++++---------------------- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 3948fb3..b06ffa3 100644 --- a/README.md +++ b/README.md @@ -2744,30 +2744,30 @@ from PIL import Image, ImageFilter, ImageEnhance, ImageDraw ``` ```python - = Image.new('', (width, height)) # Also: `color=`. - = Image.open() # Identifies format based on file contents. - = .convert('') # Converts image to the new mode. -.save() # Selects format based on the path extension. -.show() # Opens image in default preview app. + = Image.new('', (width, height)) # Also: `color=`. + = Image.open() # Identifies format based on file contents. + = .convert('') # Converts image to the new mode. +.save() # Selects format based on the path extension. +.show() # Opens image in default preview app. ``` ```python - = .getpixel((x, y)) # Returns a pixel. -.putpixel((x, y), ) # Writes a pixel to the image. - = .getdata() # Returns a flattened sequence of pixels. -.putdata() # Writes a flattened sequence of pixels. -.paste(, (x, y)) # Writes passed image to the image. + = .getpixel((x, y)) # Returns a pixel. +.putpixel((x, y), ) # Writes a pixel to the image. + = .getdata() # Returns a flattened sequence of pixels. +.putdata() # Writes a flattened sequence of pixels. +.paste(, (x, y)) # Writes passed image to the image. ``` ```python - = .resize((width, height)) # Use .width/height for original sizes. - = .filter() # ` = ImageFilter.([])` - = .enhance() # ` = ImageEnhance.()` + = .resize((width, height)) # Use .width/height for original sizes. + = .filter() # ` = ImageFilter.([])` + = .enhance() # ` = ImageEnhance.()` ``` ```python - = np.array() # Creates NumPy array from the image. - = Image.fromarray(np.uint8()) # Use .clip(0, 255) to clip the values. + = np.array() # Creates NumPy array from the image. + = Image.fromarray(np.uint8()) # Use .clip(0, 255) to clip the values. ``` ### Modes @@ -2799,13 +2799,13 @@ img.show() ### Image Draw ```python - = ImageDraw.Draw() # Object for adding 2D graphics to the image. -.point((x, y)) # Draws a point. Truncates floats into ints. -.line((x1, y1, x2, y2 [, ...])) # To get anti-aliasing use Image's resize(). -.arc((x1, y1, x2, y2), deg1, deg2) # Always draws in clockwise direction. -.rectangle((x1, y1, x2, y2)) # To rotate use Image's rotate() and paste(). -.polygon((x1, y1, x2, y2, ...)) # Last point gets connected to the first. -.ellipse((x1, y1, x2, y2)) # To rotate use Image's rotate() and paste(). + = ImageDraw.Draw() # Object for adding 2D graphics to the image. +.point((x, y)) # Draws a point. Truncates floats into ints. +.line((x1, y1, x2, y2 [, ...])) # To get anti-aliasing use Image's resize(). +.arc((x1, y1, x2, y2), deg1, deg2) # Always draws in clockwise direction. +.rectangle((x1, y1, x2, y2)) # To rotate use Image's rotate() and paste(). +.polygon((x1, y1, x2, y2, ...)) # Last point gets connected to the first. +.ellipse((x1, y1, x2, y2)) # To rotate use Image's rotate() and paste(). ``` * **Use `'fill='` to set the primary color.** * **Use `'width='` to set the width of lines or contours.** diff --git a/index.html b/index.html index ea9a4bf..5db7fc4 100644 --- a/index.html +++ b/index.html @@ -2243,24 +2243,24 @@ right = [[0.1, 0.6from PIL import Image, ImageFilter, ImageEnhance, ImageDraw -
<Image> = Image.new('<mode>', (width, height))   # Also: `color=<int/tuple/str>`.
-<Image> = Image.open(<path>)                     # Identifies format based on file contents.
-<Image> = <Image>.convert('<mode>')              # Converts image to the new mode.
-<Image>.save(<path>)                             # Selects format based on the path extension.
-<Image>.show()                                   # Opens image in default preview app.
+
<Image> = Image.new('<mode>', (width, height))  # Also: `color=<int/tuple/str>`.
+<Image> = Image.open(<path>)                    # Identifies format based on file contents.
+<Image> = <Image>.convert('<mode>')             # Converts image to the new mode.
+<Image>.save(<path>)                            # Selects format based on the path extension.
+<Image>.show()                                  # Opens image in default preview app.
 
-
<int/tuple> = <Image>.getpixel((x, y))           # Returns a pixel.
-<Image>.putpixel((x, y), <int/tuple>)            # Writes a pixel to the image.
-<ImagingCore> = <Image>.getdata()                # Returns a flattened sequence of pixels.
-<Image>.putdata(<list/ImagingCore>)              # Writes a flattened sequence of pixels.
-<Image>.paste(<Image>, (x, y))                   # Writes passed image to the image.
+
<int/tuple> = <Image>.getpixel((x, y))          # Returns a pixel.
+<Image>.putpixel((x, y), <int/tuple>)           # Writes a pixel to the image.
+<ImagingCore> = <Image>.getdata()               # Returns a flattened sequence of pixels.
+<Image>.putdata(<list/ImagingCore>)             # Writes a flattened sequence of pixels.
+<Image>.paste(<Image>, (x, y))                  # Writes passed image to the image.
 
-
<Image> = <Image>.resize((width, height))        # Use <Image>.width/height for original sizes.
-<Image> = <Image>.filter(<Filter>)               # `<Filter> = ImageFilter.<name>([<args>])`
-<Image> = <Enhance>.enhance(<float>)             # `<Enhance> = ImageEnhance.<name>(<Image>)`
+
<Image> = <Image>.resize((width, height))       # Use <Image>.width/height for original sizes.
+<Image> = <Image>.filter(<Filter>)              # `<Filter> = ImageFilter.<name>([<args>])`
+<Image> = <Enhance>.enhance(<float>)            # `<Enhance> = ImageEnhance.<name>(<Image>)`
 
-
<array> = np.array(<Image>)                      # Creates NumPy array from the image.
-<Image> = Image.fromarray(np.uint8(<array>))     # Use <array>.clip(0, 255) to clip the values.
+
<array> = np.array(<Image>)                     # Creates NumPy array from the image.
+<Image> = Image.fromarray(np.uint8(<array>))    # Use <array>.clip(0, 255) to clip the values.
 

Modes

  • '1' - 1-bit pixels, black and white, stored with one pixel per byte.
  • @@ -2286,13 +2286,13 @@ img.putdata([(add_noise(h), s, v) for h, s, v img.show()
-

Image Draw

<ImageDraw> = ImageDraw.Draw(<Image>)            # Object for adding 2D graphics to the image.
-<ImageDraw>.point((x, y))                        # Draws a point. Truncates floats into ints.
-<ImageDraw>.line((x1, y1, x2, y2 [, ...]))       # To get anti-aliasing use Image's resize().
-<ImageDraw>.arc((x1, y1, x2, y2), deg1, deg2)    # Always draws in clockwise direction.
-<ImageDraw>.rectangle((x1, y1, x2, y2))          # To rotate use Image's rotate() and paste().
-<ImageDraw>.polygon((x1, y1, x2, y2, ...))       # Last point gets connected to the first.
-<ImageDraw>.ellipse((x1, y1, x2, y2))            # To rotate use Image's rotate() and paste().
+

Image Draw

<ImageDraw> = ImageDraw.Draw(<Image>)           # Object for adding 2D graphics to the image.
+<ImageDraw>.point((x, y))                       # Draws a point. Truncates floats into ints.
+<ImageDraw>.line((x1, y1, x2, y2 [, ...]))      # To get anti-aliasing use Image's resize().
+<ImageDraw>.arc((x1, y1, x2, y2), deg1, deg2)   # Always draws in clockwise direction.
+<ImageDraw>.rectangle((x1, y1, x2, y2))         # To rotate use Image's rotate() and paste().
+<ImageDraw>.polygon((x1, y1, x2, y2, ...))      # Last point gets connected to the first.
+<ImageDraw>.ellipse((x1, y1, x2, y2))           # To rotate use Image's rotate() and paste().