本文整理汇总了Python中wand.image.Image.open方法的典型用法代码示例。如果您正苦于以下问题:Python Image.open方法的具体用法?Python Image.open怎么用?Python Image.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wand.image.Image
的用法示例。
在下文中一共展示了Image.open方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_proxy_rawpy
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import open [as 别名]
def _create_proxy_rawpy(self, source, dest, mode):
# maybe Pillow supports this file type directly?
if not self.image:
try:
self.image = Image.open(source)
except IOError:
pass
except Exception as e:
logging.error('cannot read {}: {}'.format(source, e.args[0]))
raise e
# obviously not, try decoding as Raw
if not self.image:
try:
raw = rawpy.imread(source)
rgb = raw.postprocess(use_camera_wb=True, no_auto_bright=True)
self.image = Image.fromarray(rgb)
except Exception as e:
logging.error('cannot read {}: {}'.format(source, e.args[0]))
raise e
image = self.image.copy()
if mode == self.PROXY_FULLSIZE:
pass
elif mode == self.PROXY_THUMBNAIL:
image.thumbnail(settings.THUMBNAILSIZE)
elif mode == self.PROXY_WEBSIZED:
image.thumbnail(settings.WEBSIZE)
try:
image.save(dest)
except Exception as e:
logging.error('cannot write {}: {}'.format(dest, e.args[0]))
示例2: resize_pillow
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import open [as 别名]
def resize_pillow(self, file_path, out_file):
from PIL import Image
im = Image.open(file_path)
size = (int(im.size[0] * self.scale + 0.5),
int(im.size[1] * self.scale + 0.5))
im_resized = im.resize(size, Image.ANTIALIAS)
im_resized.save(out_file, optimize=True)
示例3: make_thumbnail
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import open [as 别名]
def make_thumbnail(path, size = (200, 200)) :
name, ext = os.path.splitext(path)
try:
img = Image.open(path)
img.thumbnail(size, Image.ANTIALIAS)
thumbnail_path = "%s_thumb%s" % (name, ext)
img.save(thumbnail_path, 'JPEG')
return thumbnail_path
except:
return json.dumps({
'status': 'fail',
'error': 'unknown error while creating thumbnail'
});
示例4: str
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import open [as 别名]
strip_attrib = str(node.attrib)
imagefilename = strip_attrib[14:29]
strip_date = strip_attrib[14:24]
strip_date_format = time.strptime(strip_date, "%Y-%m-%d")
dt = time.mktime(strip_date_format)
dt = datetime.datetime.fromtimestamp(dt)
date_minus_one = dt - datetime.timedelta(days=1)
# newdate = time.mktime(date_minus_one)
next_date = str(date_minus_one).split()
next_strip_date = str(next_date[0])
print ('The image file to load is:',imagefilename)
print ('The strip date is is:',strip_date)
print ('The next strip date is is:',next_strip_date)
if (os.path.isfile(imagefilename)):
im = Image.open(imagefilename) #Can be many different formats.
print('\n==============================================\n')
print("The file ", imagefilename, " has been opened.")
text_in_panel = []
rgb_im = im.convert('RGB')
for child in node:
print(child.tag)
cropcoords = [];
for subchild in child:
# print('coord:',subchild.text)
cropcoords.append(subchild.text)
print (int(float(cropcoords[0])),int(float(cropcoords[1])),int(float(cropcoords[2])),int(float(cropcoords[3])))
leftcoord = int(float(cropcoords[0]))
uppercoord = int(float(cropcoords[1]))
rightcoord = int(float(cropcoords[2])) + int(float(cropcoords[0]))
示例5: _imagemagick
# 需要导入模块: from wand.image import Image [as 别名]
# 或者: from wand.image.Image import open [as 别名]
def _imagemagick(self, model, id, field, recipe, response, cache=None):
""" Fetches the requested field and applies the given imagemagick recipe on it.
If the record is not found or does not have the requested field,
returns a placeholder image via :meth:`~._image_placeholder`.
Sets and checks conditional response parameters:
* :mailheader:`ETag` is always set (and checked)
* :mailheader:`Last-Modified is set iif the record has a concurrency
field (``__last_update``)
The requested field is assumed to be base64-encoded image data in
all cases.
"""
user = self.env['res.users'].browse(self._uid)
o = self.env[model].sudo().browse(int(id))
if o.check_access_rights('read', raise_exception=False):
return recipe.sudo().send_file(http,field=field,model=model,id=id)
if 'website_published' in o.fields_get().keys() and o.website_published == True:
if user.has_group('base.group_website_publisher') or recipe.website_published == True:
return recipe.sudo().send_file(http,field=field,model=model,id=id)
return recipe.send_file(http,field=field,model=model,id=id)
record = self.env[model].browse(id)
if not len(record) > 0 and 'website_published' in record._fields:
record = self.env[model].sudo().search(
[('id', '=', id),
('website_published', '=', True)])
if not len(record) > 0:
return self._image_placeholder(response)
concurrency = '__last_update'
record = record.sudo()
if hasattr(record, concurrency):
server_format = openerp.tools.misc.DEFAULT_SERVER_DATETIME_FORMAT
try:
response.last_modified = datetime.datetime.strptime(
getattr(record, concurrency), server_format + '.%f')
except ValueError:
# just in case we have a timestamp without microseconds
response.last_modified = datetime.datetime.strptime(
getattr(record, concurrency), server_format)
# Field does not exist on model or field set to False
if not hasattr(record, field) and getattr(record, field) and recipe:
# FIXME: maybe a field which does not exist should be a 404?
return self._image_placeholder(response)
#TODO: Keep format of original image.
img = recipe.run(Image(blob=getattr(record, field).decode('base64'))).make_blob() #format='jpg')
response.set_etag(hashlib.sha1(img).hexdigest())
response.make_conditional(request.httprequest)
if cache:
response.cache_control.max_age = cache
response.expires = int(time.time() + cache)
# conditional request match
if response.status_code == 304:
return response
data = img.decode('base64')
image = Image.open(cStringIO.StringIO(data))
response.mimetype = Image.MIME[image.format]
filename = '%s_%s.%s' % (model.replace('.', '_'), id, str(image.format).lower())
response.headers['Content-Disposition'] = 'inline; filename="%s"' % filename
response.data = data
return response