Python PIL.Image.init() Examples

The following are 4 code examples of PIL.Image.init(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PIL.Image , or try the search function .
Example #1
Source File: identicon.py    From eoj3 with MIT License 6 votes vote down vote up
def get_bytes(self, format='PNG'):
    '''
    usage:  i = Identicon('xx')
            print(i.base64())
    return: this image's base64 code
    created by: liuzheng712
    bug report: https://github.com/liuzheng712/identicons/issues
    '''
    self.calculate()
    fp = io.BytesIO()
    self.image.encoderinfo = {}
    self.image.encoderconfig = ()

    if format.upper() not in Image.SAVE:
      Image.init()
    save_handler = Image.SAVE[format.upper()]
    try:
      save_handler(self.image, fp, '')
    finally:
      fp.seek(0)
    return fp 
Example #2
Source File: images_stub.py    From python-compat-runtime with Apache License 2.0 5 votes vote down vote up
def __init__(self, service_name='images', host_prefix=''):
    """Preloads PIL to load all modules in the unhardened environment.

    Args:
      service_name: Service name expected for all calls.
      host_prefix: the URL prefix (protocol://host:port) to preprend to
        image urls on a call to GetUrlBase.
    """
    super(ImagesServiceStub, self).__init__(
        service_name, max_request_size=MAX_REQUEST_SIZE)
    self._blob_stub = images_blob_stub.ImagesBlobStub(host_prefix)
    Image.init() 
Example #3
Source File: ocrwidget.py    From lector with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, lang, areaType, statusBar):
        QGraphicsView.__init__(self)

        self.ocrscene = OcrScene(self, lang, areaType)
        self.setScene(self.ocrscene)

        self.setCacheMode(QGraphicsView.CacheBackground)
        self.setRenderHint(QPainter.Antialiasing)
        self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)
        self.setResizeAnchor(QGraphicsView.AnchorViewCenter)

        self.setMinimumSize(200, 200)

        self.language = lang
        self.statusBar = statusBar
        self.areaType = areaType

        self.resizingArea = None
        self.resizingAreaPos = None
        self.resizingAreaRect = None
        self.resizingEdge = None
        self.resizingStartingPos = None
        self.areaBorder = float()
        self.areaTextSize = float()

        self.setCursor(Qt.CrossCursor)
        self.scene().isModified = False
        self.bResizing = False
        self.filename = None
        Image.init() 
Example #4
Source File: identicon.py    From eoj3 with MIT License 5 votes vote down vote up
def calculate(self):
    """
    Creates the identicon.
    First three bytes are used to generate the color,
    remaining bytes are used to create the drawing
    """
    color = (self.hash & 0xff, self.hash >> 8 & 0xff, self.hash >> 16 & 0xff)
    self.hash >>= 24  # skip first three bytes
    square_x = square_y = 0  # init square position
    for x in range(GRID_SIZE * (GRID_SIZE + 1) // 2):
      if self.hash & 1:
        x = BORDER_SIZE + square_x * SQUARE_SIZE
        y = BORDER_SIZE + square_y * SQUARE_SIZE
        self.draw.rectangle(
          (x, y, x + SQUARE_SIZE, y + SQUARE_SIZE),
          fill=color,
          outline=color
        )
        # following is just for mirroring
        x = BORDER_SIZE + (GRID_SIZE - 1 - square_x) * SQUARE_SIZE
        self.draw.rectangle(
          (x, y, x + SQUARE_SIZE, y + SQUARE_SIZE),
          fill=color,
          outline=color
        )
      self.hash >>= 1  # shift to right
      square_y += 1
      if square_y == GRID_SIZE:  # done with first column
        square_y = 0
        square_x += 1