Пример #1
0
def newimage(mode, size):
    """
    A minimal reimplementation of the the PIL Image.new function.
    Creates an Image object for the given mode and size.
    """
    img = Image()
    img.mode = mode
    img.size = size
    if mode == 'L':
        blank = 0
    elif mode == 'RGB':
        blank = (0, 0, 0)
    img._image_dict = {(x,y):blank\
                for x in range(size[0])\
                for y in range(size[1])}
    return img
Пример #2
0
if __name__ == '__main__':
    parser = ArgumentParser(description="Extract glyph images from a font.")
    parser.add_argument('glyphset', choices=sets.keys(),
                        help="glyphs collection key")
    parser.add_argument('font', nargs='?', default='dejavu-serif',
                        help="path to a .ttf file")
    parser.add_argument('size', type=int, nargs='?', default=14,
                        help="font size")
    args = parser.parse_args()

    folder = join('glyphs', args.glyphset)
    try:
        mkdir(folder)
    except FileExistsError:
        pass

    try:
        args.font = fonts[args.font]
    except KeyError:
        pass
    font = truetype(args.font, args.size)

    available_characters = set(c[0] for t in TTFont(args.font)['cmap'].tables
                                    for c in t.cmap.items())
    characters = set(sets[args.glyphset]) & available_characters
    for character in characters:
        image = Image()._new(font.getmask(chr(character)))
        image.save(join(folder, '{}.png'.format(character)))
    print("Extracted {} glyphs".format(len(characters)))
Пример #3
0
import pathlib
from typing import Dict, Iterator, Literal, Optional, Set, Text, Tuple, Union

import cv2
import numpy as np
from PIL.Image import Image
from PIL.Image import open as open_image

from . import clients

LOGGER = logging.getLogger(__name__)

TARGET_WIDTH = 540

_CACHED_SCREENSHOT: Dict[Literal["value"], Tuple[dt.datetime, Image]] = {
    "value": (dt.datetime.fromtimestamp(0), Image())
}


def invalidate_screeshot():
    _CACHED_SCREENSHOT["value"] = (dt.datetime.fromtimestamp(0), Image())


class g:
    last_screenshot_save_path: str = ""
    screenshot_width = TARGET_WIDTH


def screenshot(*, max_age: float = 1) -> Image:
    cached_time, _ = _CACHED_SCREENSHOT["value"]
    if cached_time < dt.datetime.now() - dt.timedelta(seconds=max_age):
Пример #4
0
def invalidate_screeshot():
    _CACHED_SCREENSHOT["value"] = (dt.datetime.fromtimestamp(0), Image())
Пример #5
0
from dataclasses import dataclass
from flask import Flask
from PIL.Image import Image  # type: ignore
from typing import Type

app = Flask()


class n(Image):
    ...


@dataclass
class A():
    x: int
    y: str


a = A(1, "str")

b: 'Image' = Image("str")

reveal_type(b)
Пример #6
0
 def gr(self, grap):
     self._gr = grap
     self._pi = Image(self._gr)
Пример #7
0
 def test_add_pixel(self):
     with patch.object(Image, 'putpixel', return_value=None) as mock_method:
         img = Image()
         add_pixel(img, 5, 3, 0xffffff)
         mock_method.assert_called_with((2, 1), 0xffffff)
Пример #8
0
class PetstoreClientWithTyping(PetAPI, StoreAPI, UserAPI):
    """Swagger Petstore client."""


#
# These checks only validate that typing works, they are not meant
# to be executed
#
client = PetstoreClientWithTyping('http://example.com', backend='requests')

assert client.add_pet({'a': {'b': 'c'}}) is None
assert client.update_pet({'a': {'b': 'c'}}) is None
assert client.find_pet_by_status() == [{'a': {'b': 'c'}}]
assert client.find_pet_by_status_xml() == ET.Element('pet')
assert client.find_pet_by_id('123') == {'a': {'b': 'c'}}
assert client.update_pet_by_id('123', {'a': {'b': 'c'}}) is None
assert client.delete_pet('123') is None
assert client.upload_pet_image('123', Image()) is None
assert client.get_inventory() == {'a': {'b': 'c'}}
assert client.place_order({'a': {'b': 'c'}}) is None
assert client.get_order('a') == {'a': {'b': 'c'}}
assert client.delete_order('a') is None
assert client.create_user({'a': {'b': 'c'}}) is True
assert client.create_users_from_array([{'a': {'b': 'c'}}]) is None
assert client.create_users_from_list([{'a': {'b': 'c'}}]) is None
assert client.login('a', 'b') == {'a': {'b': 'c'}}
assert client.logout() == {'a': {'b': 'c'}}
assert client.get_user('a') == {'a': {'b': 'c'}}
assert client.update_user('a', {'a': {'b': 'c'}}) == {'a': {'b': 'c'}}
assert client.delete_user('a') is None
Пример #9
0
def setup(bot):
    bot.add_cog(Image(bot))