本文整理匯總了Python中PIL.Image.init方法的典型用法代碼示例。如果您正苦於以下問題:Python Image.init方法的具體用法?Python Image.init怎麽用?Python Image.init使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PIL.Image
的用法示例。
在下文中一共展示了Image.init方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_bytes
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import init [as 別名]
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
示例2: __init__
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import init [as 別名]
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()
示例3: __init__
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import init [as 別名]
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()
示例4: calculate
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import init [as 別名]
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