id
int64
0
190k
prompt
stringlengths
21
13.4M
docstring
stringlengths
1
12k
167,565
import calendar import codecs import collections import mmap import os import re import time import zlib def encode_text(s): return codecs.BOM_UTF16_BE + s.encode("utf_16_be") class PdfName: def __init__(self, name): if isinstance(name, PdfName): self.name = name.name elif isinstance...
null
167,566
import math import numbers from . import Image, ImageColor, ImageFont def _color_diff(color1, color2): """ Uses 1-norm distance to calculate difference between two values. """ if isinstance(color2, tuple): return sum(abs(color1[i] - color2[i]) for i in range(0, len(color2))) else: re...
(experimental) Fills a bounded region with a given color. :param image: Target image. :param xy: Seed position (a 2-item coordinate tuple). See :ref:`coordinate-system`. :param value: Fill color. :param border: Optional border value. If given, the region consists of pixels with a color different from the border color. ...
167,567
import math import numbers from . import Image, ImageColor, ImageFont The provided code snippet includes necessary dependencies for implementing the `_compute_regular_polygon_vertices` function. Write a Python function `def _compute_regular_polygon_vertices(bounding_circle, n_sides, rotation)` to solve the following p...
Generate a list of vertices for a 2D regular polygon. :param bounding_circle: The bounding circle is a tuple defined by a point and radius. The polygon is inscribed in this circle. (e.g. ``bounding_circle=(x, y, r)`` or ``((x, y), r)``) :param n_sides: Number of sides (e.g. ``n_sides=3`` for a triangle, ``6`` for a hex...
167,568
import tkinter from io import BytesIO from . import Image _pilbitmap_ok = None class BitmapImage: """ A Tkinter-compatible bitmap image. This can be used everywhere Tkinter expects an image object. The given image must have mode "1". Pixels having value 0 are treated as transparent. Options, if a...
null
167,569
import tkinter from io import BytesIO from . import Image class Image: """ This class represents an image object. To create :py:class:`~PIL.Image.Image` objects, use the appropriate factory functions. There's hardly ever any reason to call the Image constructor directly. * :py:func:`~PIL.Ima...
null
167,570
import tkinter from io import BytesIO from . import Image class Image: """ This class represents an image object. To create :py:class:`~PIL.Image.Image` objects, use the appropriate factory functions. There's hardly ever any reason to call the Image constructor directly. * :py:func:`~PIL.Ima...
Copies the contents of a PhotoImage to a PIL image memory.
167,571
import tkinter from io import BytesIO from . import Image class PhotoImage: """ A Tkinter-compatible photo image. This can be used everywhere Tkinter expects an image object. If the image is an RGBA image, pixels having alpha 0 are treated as transparent. The constructor takes either a PIL image, ...
Helper for the Image.show method.
167,572
class Iterator: """ This class implements an iterator object that can be used to loop over an image sequence. You can use the ``[]`` operator to access elements by index. This operator will raise an :py:exc:`IndexError` if you try to access a nonexistent frame. :param im: An image object. ...
Applies a given function to all frames in an image or a list of images. The frames are returned as a list of separate images. :param im: An image, or a list of images. :param func: The function to apply to all of the image frames. :returns: A list of images.
167,573
import os import struct import sys from PIL import Image, ImageFile def isSpiderImage(filename): with open(filename, "rb") as fp: f = fp.read(92) # read 23 * 4 bytes t = struct.unpack(">23f", f) # try big-endian first hdrlen = isSpiderHeader(t) if hdrlen == 0: t = struct.unpack("<23f",...
create a list of :py:class:`~PIL.Image.Image` objects for use in a montage
167,574
import os import struct import sys from PIL import Image, ImageFile class SpiderImageFile(ImageFile.ImageFile): format = "SPIDER" format_description = "Spider 2D image" _close_exclusive_fp_after_loading = False def _open(self): # check header n = 27 * 4 # read 27 float values f ...
null
167,575
import os import tempfile from . import Image, ImageFile from ._binary import i8 from ._binary import i16be as i16 from ._binary import i32be as i32 from ._binary import o8 def i(c): return i32((PAD + c)[-4:]) def i8(c): return c if c.__class__ is int else c[0] def dump(c): for i in c: print("%02x...
null
167,576
import os import tempfile from . import Image, ImageFile from ._binary import i8 from ._binary import i16be as i16 from ._binary import i32be as i32 from ._binary import o8 class IptcImageFile(ImageFile.ImageFile): format = "IPTC" format_description = "IPTC/NAA" def getint(self, key): return i(self....
Get IPTC information from TIFF, JPEG, or IPTC file. :param im: An image containing IPTC data. :returns: A dictionary containing IPTC information, or None if no IPTC information block was found.
167,577
from io import BytesIO from . import Image, ImageFile _VP8_MODES_BY_IDENTIFIER = { b"VP8 ": "RGB", b"VP8X": "RGBA", b"VP8L": "RGBA", # lossless } if SUPPORTED: Image.register_save(WebPImageFile.format, _save) if _webp.HAVE_WEBPANIM: Image.register_save_all(WebPImageFile.format, _save_all) ...
null
167,578
from io import BytesIO from . import Image, ImageFile try: from . import _webp SUPPORTED = True except ImportError: SUPPORTED = False _VALID_WEBP_MODES = {"RGBX": True, "RGBA": True, "RGB": True} def _save(im, fp, filename): lossless = im.encoderinfo.get("lossless", False) quality = im.encoderinfo.g...
null
167,579
import io import logging from . import Image, ImageFile, ImagePalette from ._binary import i16le as i16 from ._binary import o8 from ._binary import o16le as o16 def _accept(prefix): return prefix[0] == 10 and prefix[1] in [0, 2, 3, 5]
null
167,580
import io import logging from . import Image, ImageFile, ImagePalette from ._binary import i16le as i16 from ._binary import o8 from ._binary import o16le as o16 logger = logging.getLogger(__name__) SAVE = { # mode: (version, bits, planes, raw mode) "1": (2, 1, 1, "1"), "L": (5, 8, 1, "L"), "P": (5, 8, ...
null
167,581
import io import itertools import struct import sys from . import Image from ._util import isPath ERRORS = { -1: "image buffer overrun error", -2: "decoding error", -3: "unknown error", -8: "bad configuration", -9: "out of memory error", } class Image: """ This class represents an image obj...
null
167,582
import io import struct from . import Image, ImageFile from ._binary import i16le as i16 from ._binary import o16le as o16 def _accept(prefix): return prefix[:4] in [b"DanM", b"LinS"]
null
167,583
import io import struct from . import Image, ImageFile from ._binary import i16le as i16 from ._binary import o16le as o16 class ImageFile(Image.Image): """Base class for image file format handlers.""" def __init__(self, fp=None, filename=None): super().__init__() self._min_frame = 0 ...
null
167,584
import olefile from . import Image, TiffImagePlugin def _accept(prefix): return prefix[:8] == olefile.MAGIC
null
167,585
import io import os import time from . import Image, ImageFile, ImageSequence, PdfParser, __version__ def _save(im, fp, filename, save_all=False): is_appending = im.encoderinfo.get("append", False) if is_appending: existing_pdf = PdfParser.PdfParser(f=fp, filename=filename, mode="r+b") else: ...
null
167,586
import io import os import struct import sys from PIL import Image, ImageFile, PngImagePlugin, features HEADERSIZE = 8 def nextheader(fobj): return struct.unpack(">4sI", fobj.read(HEADERSIZE))
null
167,587
import io import os import struct import sys from PIL import Image, ImageFile, PngImagePlugin, features def read_32(fobj, start_length, size): """ Read a 32bit RGB icon resource. Seems to be either uncompressed or an RLE packbits-like scheme. """ (start, length) = start_length fobj.seek(start) ...
null
167,588
import io import os import struct import sys from PIL import Image, ImageFile, PngImagePlugin, features Image.register_open(IcnsImageFile.format, IcnsImageFile, _accept) Image.register_extension(IcnsImageFile.format, ".icns") Image.register_save(IcnsImageFile.format, _save) Image.register_mime(IcnsImageFile.format, "im...
null
167,589
import io import os import struct import sys from PIL import Image, ImageFile, PngImagePlugin, features enable_jpeg2k = features.check_codec("jpg_2000") if enable_jpeg2k: from PIL import Jpeg2KImagePlugin Image.register_open(IcnsImageFile.format, IcnsImageFile, _accept) Image.register_extension(IcnsImageFile.format...
null
167,590
import io import os import struct import sys from PIL import Image, ImageFile, PngImagePlugin, features MAGIC = b"icns" HEADERSIZE = 8 The provided code snippet includes necessary dependencies for implementing the `_save` function. Write a Python function `def _save(im, fp, filename)` to solve the following problem: S...
Saves the image as a series of PNG files, that are then combined into a .icns file.
167,591
import io import os import struct import sys from PIL import Image, ImageFile, PngImagePlugin, features MAGIC = b"icns" def _accept(prefix): return prefix[:4] == MAGIC
null
167,592
from . import Image, ImageFile def _accept(prefix): return prefix[0:1] == b"P" and prefix[1] in b"0456y"
null
167,593
from . import Image, ImageFile class ImageFile(Image.Image): """Base class for image file format handlers.""" def __init__(self, fp=None, filename=None): super().__init__() self._min_frame = 0 self.custom_mimetype = None self.tile = None """ A list of tile descriptor...
null
167,594
from struct import pack, unpack_from The provided code snippet includes necessary dependencies for implementing the `i16le` function. Write a Python function `def i16le(c, o=0)` to solve the following problem: Converts a 2-bytes (16 bits) string to an unsigned integer. :param c: string containing bytes to convert :par...
Converts a 2-bytes (16 bits) string to an unsigned integer. :param c: string containing bytes to convert :param o: offset of bytes to convert in string
167,595
from struct import pack, unpack_from The provided code snippet includes necessary dependencies for implementing the `si16le` function. Write a Python function `def si16le(c, o=0)` to solve the following problem: Converts a 2-bytes (16 bits) string to a signed integer. :param c: string containing bytes to convert :para...
Converts a 2-bytes (16 bits) string to a signed integer. :param c: string containing bytes to convert :param o: offset of bytes to convert in string
167,596
from struct import pack, unpack_from The provided code snippet includes necessary dependencies for implementing the `si16be` function. Write a Python function `def si16be(c, o=0)` to solve the following problem: Converts a 2-bytes (16 bits) string to a signed integer, big endian. :param c: string containing bytes to c...
Converts a 2-bytes (16 bits) string to a signed integer, big endian. :param c: string containing bytes to convert :param o: offset of bytes to convert in string
167,597
from struct import pack, unpack_from The provided code snippet includes necessary dependencies for implementing the `i32le` function. Write a Python function `def i32le(c, o=0)` to solve the following problem: Converts a 4-bytes (32 bits) string to an unsigned integer. :param c: string containing bytes to convert :par...
Converts a 4-bytes (32 bits) string to an unsigned integer. :param c: string containing bytes to convert :param o: offset of bytes to convert in string
167,598
from struct import pack, unpack_from The provided code snippet includes necessary dependencies for implementing the `si32le` function. Write a Python function `def si32le(c, o=0)` to solve the following problem: Converts a 4-bytes (32 bits) string to a signed integer. :param c: string containing bytes to convert :para...
Converts a 4-bytes (32 bits) string to a signed integer. :param c: string containing bytes to convert :param o: offset of bytes to convert in string
167,599
from struct import pack, unpack_from def i16be(c, o=0): return unpack_from(">H", c, o)[0]
null
167,600
from struct import pack, unpack_from def i32be(c, o=0): return unpack_from(">I", c, o)[0]
null
167,601
from struct import pack, unpack_from def o16le(i): return pack("<H", i)
null
167,602
from struct import pack, unpack_from def o32le(i): return pack("<I", i)
null
167,603
from struct import pack, unpack_from def o32be(i): return pack(">I", i)
null
167,604
from . import Image, ImageFile, ImagePalette from ._binary import i32be as i32 def _accept(prefix): return len(prefix) >= 4 and i32(prefix) == 0x59A66A95
null
167,605
from . import Image, ImageFile from ._binary import i16le as i16 def _accept(prefix): return prefix[:4] == b"\200\350\000\000"
null
167,606
from . import Image, ImageFile from ._binary import i32le as i32 class WalImageFile(ImageFile.ImageFile): format = "WAL" format_description = "Quake2 Texture" def _open(self): self.mode = "P" # read header fields header = self.fp.read(32 + 24 + 32 + 12) self._size = i32(heade...
Load texture from a Quake2 WAL texture file. By default, a Quake2 standard palette is attached to the texture. To override the palette, use the :py:func:`PIL.Image.Image.putpalette()` method. :param filename: WAL file name, or an opened file handle. :returns: An image instance.
167,607
import itertools import math import os import subprocess from . import Image, ImageChops, ImageFile, ImagePalette, ImageSequence from ._binary import i16le as i16 from ._binary import o8 from ._binary import o16le as o16 def _accept(prefix): return prefix[:6] in [b"GIF87a", b"GIF89a"]
null
167,608
import itertools import math import os import subprocess from . import Image, ImageChops, ImageFile, ImagePalette, ImageSequence from ._binary import i16le as i16 from ._binary import o8 from ._binary import o16le as o16 def _save(im, fp, filename, save_all=False): def _save_all(im, fp, filename): _save(im, fp, fi...
null
167,609
import itertools import math import os import subprocess from . import Image, ImageChops, ImageFile, ImagePalette, ImageSequence from ._binary import i16le as i16 from ._binary import o8 from ._binary import o16le as o16 def _save_netpbm(im, fp, filename): # Unused by default. # To use, uncomment the register...
null
167,610
import itertools import math import os import subprocess from . import Image, ImageChops, ImageFile, ImagePalette, ImageSequence from ._binary import i16le as i16 from ._binary import o8 from ._binary import o16le as o16 def _normalize_palette(im, palette, info): """ Normalizes the palette for image. - Se...
Legacy Method to get Gif data from image. Warning:: May modify image data. :param im: Image object :param palette: bytes object containing the source palette, or .... :param info: encoderinfo :returns: tuple of(list of header items, optimized palette)
167,611
import sys from PIL import Image try: from PIL import _imagingcms except ImportError as ex: # Allow error import for doc purposes, but error out when accessing # anything in core. from ._util import deferred_error _imagingcms = deferred_error(ex) core = _imagingcms class ImageCmsProfile: def __i...
(experimental) Fetches the profile for the current display device. :returns: ``None`` if the profile is not known.
167,612
import sys from PIL import Image INTENT_PERCEPTUAL = 0 _MAX_FLAG = 0 class ImageCmsProfile: def __init__(self, profile): """ :param profile: Either a string representing a filename, a file like object containing a profile or a low-level profile object """ if i...
(pyCMS) Applies an ICC transformation to a given image, mapping from ``inputProfile`` to ``outputProfile``. If the input or output profiles specified are not valid filenames, a :exc:`PyCMSError` will be raised. If ``inPlace`` is ``True`` and ``outputMode != im.mode``, a :exc:`PyCMSError` will be raised. If an error occ...
167,613
import sys from PIL import Image class ImageCmsProfile: def __init__(self, profile): """ :param profile: Either a string representing a filename, a file like object containing a profile or a low-level profile object """ if isinstance(profile, str): ...
(pyCMS) Opens an ICC profile file. The PyCMSProfile object can be passed back into pyCMS for use in creating transforms and such (as in ImageCms.buildTransformFromOpenProfiles()). If ``profileFilename`` is not a valid filename for an ICC profile, a :exc:`PyCMSError` will be raised. :param profileFilename: String, as a ...
167,614
import sys from PIL import Image INTENT_PERCEPTUAL = 0 _MAX_FLAG = 0 class ImageCmsProfile: def __init__(self, profile): """ :param profile: Either a string representing a filename, a file like object containing a profile or a low-level profile object """ if i...
(pyCMS) Builds an ICC transform mapping from the ``inputProfile`` to the ``outputProfile``. Use applyTransform to apply the transform to a given image. If the input or output profiles specified are not valid filenames, a :exc:`PyCMSError` will be raised. If an error occurs during creation of the transform, a :exc:`PyCM...
167,615
import sys from PIL import Image INTENT_PERCEPTUAL = 0 INTENT_ABSOLUTE_COLORIMETRIC = 3 FLAGS = { "MATRIXINPUT": 1, "MATRIXOUTPUT": 2, "MATRIXONLY": (1 | 2), "NOWHITEONWHITEFIXUP": 4, # Don't hot fix scum dot # Don't create prelinearization tables on precalculated transforms # (internal use): ...
(pyCMS) Builds an ICC transform mapping from the ``inputProfile`` to the ``outputProfile``, but tries to simulate the result that would be obtained on the ``proofProfile`` device. If the input, output, or proof profiles specified are not valid filenames, a :exc:`PyCMSError` will be raised. If an error occurs during cre...
167,616
import sys from PIL import Image class PyCMSError(Exception): """(pyCMS) Exception class. This is used for all errors in the pyCMS API.""" pass The provided code snippet includes necessary dependencies for implementing the `applyTransform` function. Write a Python function `def applyTransform(im, transform...
(pyCMS) Applies a transform to a given image. If ``im.mode != transform.inMode``, a :exc:`PyCMSError` is raised. If ``inPlace`` is ``True`` and ``transform.inMode != transform.outMode``, a :exc:`PyCMSError` is raised. If ``im.mode``, ``transform.inMode`` or ``transform.outMode`` is not supported by pyCMSdll or the prof...
167,617
import sys from PIL import Image core = _imagingcms class PyCMSError(Exception): """(pyCMS) Exception class. This is used for all errors in the pyCMS API.""" pass The provided code snippet includes necessary dependencies for implementing the `createProfile` function. Write a Python function `def createProf...
(pyCMS) Creates a profile. If colorSpace not in ``["LAB", "XYZ", "sRGB"]``, a :exc:`PyCMSError` is raised. If using LAB and ``colorTemp`` is not a positive integer, a :exc:`PyCMSError` is raised. If an error occurs while creating the profile, a :exc:`PyCMSError` is raised. Use this function to create common profiles on...
167,618
import sys from PIL import Image class ImageCmsProfile: def __init__(self, profile): """ :param profile: Either a string representing a filename, a file like object containing a profile or a low-level profile object """ if isinstance(profile, str): ...
(pyCMS) Gets the internal product name for the given profile. If ``profile`` isn't a valid CmsProfile object or filename to a profile, a :exc:`PyCMSError` is raised If an error occurs while trying to obtain the name tag, a :exc:`PyCMSError` is raised. Use this function to obtain the INTERNAL name of the profile (stored...
167,619
import sys from PIL import Image class ImageCmsProfile: def __init__(self, profile): """ :param profile: Either a string representing a filename, a file like object containing a profile or a low-level profile object """ if isinstance(profile, str): ...
(pyCMS) Gets the internal product information for the given profile. If ``profile`` isn't a valid CmsProfile object or filename to a profile, a :exc:`PyCMSError` is raised. If an error occurs while trying to obtain the info tag, a :exc:`PyCMSError` is raised. Use this function to obtain the information stored in the pr...
167,620
import sys from PIL import Image class ImageCmsProfile: def __init__(self, profile): """ :param profile: Either a string representing a filename, a file like object containing a profile or a low-level profile object """ if isinstance(profile, str): ...
(pyCMS) Gets the copyright for the given profile. If ``profile`` isn't a valid CmsProfile object or filename to a profile, a :exc:`PyCMSError` is raised. If an error occurs while trying to obtain the copyright tag, a :exc:`PyCMSError` is raised. Use this function to obtain the information stored in the profile's copyri...
167,621
import sys from PIL import Image class ImageCmsProfile: def __init__(self, profile): """ :param profile: Either a string representing a filename, a file like object containing a profile or a low-level profile object """ if isinstance(profile, str): ...
(pyCMS) Gets the manufacturer for the given profile. If ``profile`` isn't a valid CmsProfile object or filename to a profile, a :exc:`PyCMSError` is raised. If an error occurs while trying to obtain the manufacturer tag, a :exc:`PyCMSError` is raised. Use this function to obtain the information stored in the profile's ...
167,622
import sys from PIL import Image class ImageCmsProfile: def __init__(self, profile): """ :param profile: Either a string representing a filename, a file like object containing a profile or a low-level profile object """ if isinstance(profile, str): ...
(pyCMS) Gets the model for the given profile. If ``profile`` isn't a valid CmsProfile object or filename to a profile, a :exc:`PyCMSError` is raised. If an error occurs while trying to obtain the model tag, a :exc:`PyCMSError` is raised. Use this function to obtain the information stored in the profile's model tag. :pa...
167,623
import sys from PIL import Image class ImageCmsProfile: def __init__(self, profile): """ :param profile: Either a string representing a filename, a file like object containing a profile or a low-level profile object """ if isinstance(profile, str): ...
(pyCMS) Gets the description for the given profile. If ``profile`` isn't a valid CmsProfile object or filename to a profile, a :exc:`PyCMSError` is raised. If an error occurs while trying to obtain the description tag, a :exc:`PyCMSError` is raised. Use this function to obtain the information stored in the profile's de...
167,624
import sys from PIL import Image class ImageCmsProfile: def __init__(self, profile): """ :param profile: Either a string representing a filename, a file like object containing a profile or a low-level profile object """ if isinstance(profile, str): ...
(pyCMS) Gets the default intent name for the given profile. If ``profile`` isn't a valid CmsProfile object or filename to a profile, a :exc:`PyCMSError` is raised. If an error occurs while trying to obtain the default intent, a :exc:`PyCMSError` is raised. Use this function to determine the default (and usually best op...
167,625
import sys from PIL import Image class ImageCmsProfile: def __init__(self, profile): """ :param profile: Either a string representing a filename, a file like object containing a profile or a low-level profile object """ if isinstance(profile, str): ...
(pyCMS) Checks if a given intent is supported. Use this function to verify that you can use your desired ``intent`` with ``profile``, and that ``profile`` can be used for the input/output/proof profile as you desire. Some profiles are created specifically for one "direction", can cannot be used for others. Some profile...
167,626
import sys from PIL import Image VERSION = "1.0.0 pil" core = _imagingcms class Image: """ This class represents an image object. To create :py:class:`~PIL.Image.Image` objects, use the appropriate factory functions. There's hardly ever any reason to call the Image constructor directly. * :p...
(pyCMS) Fetches versions.
167,627
import functools import operator import re from . import Image def _lut(image, lut): if image.mode == "P": # FIXME: apply to lookup table, not image data raise NotImplementedError("mode P support coming soon") elif image.mode in ("L", "RGB"): if image.mode == "RGB" and len(lut) == 256: ...
Maximize (normalize) image contrast. This function calculates a histogram of the input image (or mask region), removes ``cutoff`` percent of the lightest and darkest pixels from the histogram, and remaps the image so that the darkest pixel becomes black (0), and the lightest becomes white (255). :param image: The image...
167,628
import functools import operator import re from . import Image def _color(color, mode): if isinstance(color, str): from . import ImageColor color = ImageColor.getcolor(color, mode) return color def _lut(image, lut): if image.mode == "P": # FIXME: apply to lookup table, not image data...
Colorize grayscale image. This function calculates a color wedge which maps all black pixels in the source image to the first color and all white pixels to the second color. If ``mid`` is specified, it uses three-color mapping. The ``black`` and ``white`` arguments should be RGB tuples or color names; optionally you ca...
167,629
import functools import operator import re from . import Image def contain(image, size, method=Image.BICUBIC): """ Returns a resized version of the image, set to the maximum width and height within the requested size, while maintaining the original aspect ratio. :param image: The image to resize and cro...
Returns a resized and padded version of the image, expanded to fill the requested aspect ratio and size. :param image: The image to resize and crop. :param size: The requested output size in pixels, given as a (width, height) tuple. :param method: Resampling method to use. Default is :py:attr:`PIL.Image.BICUBIC`. See :...
167,630
import functools import operator import re from . import Image class Image: """ This class represents an image object. To create :py:class:`~PIL.Image.Image` objects, use the appropriate factory functions. There's hardly ever any reason to call the Image constructor directly. * :py:func:`~PI...
Deform the image. :param image: The image to deform. :param deformer: A deformer object. Any object that implements a ``getmesh`` method can be used. :param resample: An optional resampling filter. Same values possible as in the PIL.Image.transform function. :return: An image.
167,631
import functools import operator import re from . import Image def _lut(image, lut): if image.mode == "P": # FIXME: apply to lookup table, not image data raise NotImplementedError("mode P support coming soon") elif image.mode in ("L", "RGB"): if image.mode == "RGB" and len(lut) == 256: ...
Equalize the image histogram. This function applies a non-linear mapping to the input image, in order to create a uniform distribution of grayscale values in the output image. :param image: The image to equalize. :param mask: An optional mask. If given, only the pixels selected by the mask are included in the analysis....
167,632
import functools import operator import re from . import Image def _border(border): if isinstance(border, tuple): if len(border) == 2: left, top = right, bottom = border elif len(border) == 4: left, top, right, bottom = border else: left = top = right = bottom = b...
Add border to the image :param image: The image to expand. :param border: Border width, in pixels. :param fill: Pixel fill value (a color value). Default is 0 (black). :return: An image.
167,633
import functools import operator import re from . import Image def crop(image, border=0): """ Remove border from image. The same amount of pixels are removed from all four sides. This function works on all image modes. .. seealso:: :py:meth:`~PIL.Image.Image.crop` :param image: The image to crop. ...
Returns a resized and cropped version of the image, cropped to the requested aspect ratio and size. This function was contributed by Kevin Cazabon. :param image: The image to resize and crop. :param size: The requested output size in pixels, given as a (width, height) tuple. :param method: Resampling method to use. Def...
167,634
import functools import operator import re from . import Image class Image: """ This class represents an image object. To create :py:class:`~PIL.Image.Image` objects, use the appropriate factory functions. There's hardly ever any reason to call the Image constructor directly. * :py:func:`~PI...
Flip the image vertically (top to bottom). :param image: The image to flip. :return: An image.
167,635
import functools import operator import re from . import Image The provided code snippet includes necessary dependencies for implementing the `grayscale` function. Write a Python function `def grayscale(image)` to solve the following problem: Convert the image to grayscale. :param image: The image to convert. :return:...
Convert the image to grayscale. :param image: The image to convert. :return: An image.
167,636
import functools import operator import re from . import Image class Image: """ This class represents an image object. To create :py:class:`~PIL.Image.Image` objects, use the appropriate factory functions. There's hardly ever any reason to call the Image constructor directly. * :py:func:`~PI...
Flip image horizontally (left to right). :param image: The image to mirror. :return: An image.
167,637
import functools import operator import re from . import Image def _lut(image, lut): if image.mode == "P": # FIXME: apply to lookup table, not image data raise NotImplementedError("mode P support coming soon") elif image.mode in ("L", "RGB"): if image.mode == "RGB" and len(lut) == 256: ...
Reduce the number of bits for each color channel. :param image: The image to posterize. :param bits: The number of bits to keep for each channel (1-8). :return: An image.
167,638
import functools import operator import re from . import Image def _lut(image, lut): if image.mode == "P": # FIXME: apply to lookup table, not image data raise NotImplementedError("mode P support coming soon") elif image.mode in ("L", "RGB"): if image.mode == "RGB" and len(lut) == 256: ...
Invert all pixel values above a threshold. :param image: The image to solarize. :param threshold: All pixels above this greyscale level are inverted. :return: An image.
167,639
import functools import operator import re from . import Image class Image: """ This class represents an image object. To create :py:class:`~PIL.Image.Image` objects, use the appropriate factory functions. There's hardly ever any reason to call the Image constructor directly. * :py:func:`~PI...
If an image has an EXIF Orientation tag, return a new image that is transposed accordingly. Otherwise, return a copy of the image. :param image: The image to transpose. :return: An image.
167,640
import struct from . import Image, ImageFile def _accept(s): return s[:8] == b"\x00\x00\x00\x00\x00\x00\x00\x04"
null
167,641
import re from . import Image, ImageFile, ImagePalette from ._binary import o8 def _accept(prefix): return prefix[:9] == b"/* XPM */"
null
167,642
import io import os import re import subprocess import sys import tempfile from . import Image, ImageFile from ._binary import i32le as i32 gs_windows_binary = None if sys.platform.startswith("win"): import shutil for binary in ("gswin32c", "gswin64c", "gs"): if shutil.which(binary) is not None: ...
null
167,643
import io import os import re import subprocess import sys import tempfile from . import Image, ImageFile from ._binary import i32le as i32 gs_windows_binary = None if sys.platform.startswith("win"): import shutil for binary in ("gswin32c", "gswin64c", "gs"): if shutil.which(binary) is not None: ...
Render an image using Ghostscript
167,644
import io import os import re import subprocess import sys import tempfile from . import Image, ImageFile from ._binary import i32le as i32 def _accept(prefix): return prefix[:4] == b"%!PS" or (len(prefix) >= 4 and i32(prefix) == 0xC6D3D0C5)
null
167,645
import io import os import re import subprocess import sys import tempfile from . import Image, ImageFile from ._binary import i32le as i32 class ImageFile(Image.Image): """Base class for image file format handlers.""" def __init__(self, fp=None, filename=None): super().__init__() self._min_f...
EPS Writer for the Python Imaging Library.
167,646
from . import FontFile, Image class Image: """ This class represents an image object. To create :py:class:`~PIL.Image.Image` objects, use the appropriate factory functions. There's hardly ever any reason to call the Image constructor directly. * :py:func:`~PIL.Image.open` * :py:func:`~PI...
null
167,647
import warnings from . import Image, ImageFile, ImagePalette from ._binary import i16le as i16 from ._binary import o8 from ._binary import o16le as o16 SAVE = { "1": ("1", 1, 0, 3), "L": ("L", 8, 0, 3), "LA": ("LA", 16, 0, 3), "P": ("P", 8, 1, 1), "RGB": ("BGR", 24, 0, 2), "RGBA": ("BGRA", 32, ...
null
167,648
from . import Image, ImageFile _handler = None The provided code snippet includes necessary dependencies for implementing the `register_handler` function. Write a Python function `def register_handler(handler)` to solve the following problem: Install application-specific GRIB image handler. :param handler: Handler obj...
Install application-specific GRIB image handler. :param handler: Handler object.
167,649
from . import Image, ImageFile def _accept(prefix): return prefix[0:4] == b"GRIB" and prefix[7] == 1
null
167,650
from . import Image, ImageFile _handler = None def _save(im, fp, filename): if _handler is None or not hasattr("_handler", "save"): raise OSError("GRIB save handler not installed") _handler.save(im, fp, filename)
null
167,651
import builtins from . import Image, _imagingmath def _isconstant(v): return isinstance(v, (int, float))
null
167,652
import builtins from . import Image, _imagingmath class _Operand: """Wraps an image operand, providing standard operators""" def __init__(self, im): self.im = im def __fixup(self, im1): # convert image to suitable mode if isinstance(im1, _Operand): # argument was an image...
null
167,653
import builtins from . import Image, _imagingmath class _Operand: """Wraps an image operand, providing standard operators""" def __init__(self, im): self.im = im def __fixup(self, im1): # convert image to suitable mode if isinstance(im1, _Operand): # argument was an image...
null
167,654
import builtins from . import Image, _imagingmath def imagemath_equal(self, other): return self.apply("eq", self, other, mode="I")
null
167,655
import builtins from . import Image, _imagingmath def imagemath_notequal(self, other): return self.apply("ne", self, other, mode="I")
null
167,656
import builtins from . import Image, _imagingmath def imagemath_min(self, other): return self.apply("min", self, other)
null
167,657
import builtins from . import Image, _imagingmath def imagemath_max(self, other): return self.apply("max", self, other)
null
167,658
import builtins from . import Image, _imagingmath class _Operand: """Wraps an image operand, providing standard operators""" def __init__(self, im): self.im = im def __fixup(self, im1): # convert image to suitable mode if isinstance(im1, _Operand): # argument was an image...
null
167,659
import builtins from . import Image, _imagingmath class _Operand: """Wraps an image operand, providing standard operators""" def __init__(self, im): self.im = im def __fixup(self, im1): # convert image to suitable mode if isinstance(im1, _Operand): # argument was an image...
Evaluates an image expression. :param expression: A string containing a Python-style expression. :param options: Values to add to the evaluation context. You can either use a dictionary, or one or more keyword arguments. :return: The evaluated expression. This is usually an image object, but can also be an integer, a f...
167,660
import sys from io import BytesIO from . import Image from ._util import isPath def fromqimage(im): def fromqpixmap(im): return fromqimage(im) # buffer = QBuffer() # buffer.open(QIODevice.ReadWrite) # # im.save(buffer) # # What if png doesn't support some image features like animation? # im.sav...
null
167,661
import sys from io import BytesIO from . import Image from ._util import isPath for qt_version, qt_module in qt_versions: try: if qt_module == "PyQt6": from PyQt6.QtCore import QBuffer, QIODevice from PyQt6.QtGui import QImage, QPixmap, qRgba elif qt_module == "PySide6": ...
null
167,662
import sys from io import BytesIO from . import Image from ._util import isPath def toqimage(im): return ImageQt(im) def toqpixmap(im): # # This doesn't work. For now using a dumb approach. # im_data = _toqclass_helper(im) # result = QPixmap(im_data["size"][0], im_data["size"][1]) # result.loadFrom...
null
167,663
from collections import namedtuple class TagInfo(namedtuple("_TagInfo", "value name type length enum")): __slots__ = [] def __new__(cls, value=None, name="unknown", type=None, length=None, enum=None): return super().__new__(cls, value, name, type, length, enum or {}) def cvt_enum(self, value): ...
null
167,664
import re from . import Image, ImageFile def _accept(prefix): return prefix.lstrip()[:7] == b"#define"
null