本文整理汇总了Python中photo.Photo.resize方法的典型用法代码示例。如果您正苦于以下问题:Python Photo.resize方法的具体用法?Python Photo.resize怎么用?Python Photo.resize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类photo.Photo
的用法示例。
在下文中一共展示了Photo.resize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_product_photo
# 需要导入模块: from photo import Photo [as 别名]
# 或者: from photo.Photo import resize [as 别名]
def save_product_photo(self, photo, main=False):
if type(photo) is type(''):
return False
file_content = photo.file.read()
if len(file_content) == 0:
return False
filename, ext = os.path.splitext(photo.filename)
filename = unicodedata.normalize('NFD', filename).encode('ascii', 'ignore')
md5_ = md5(str(file_content)).hexdigest()
new_filename = md5_ + '_' + filename.lower() + ext.lower()
if not os.path.exists(Photo.BASE_STORAGE_PATH + new_filename[0]):
os.makedirs(Photo.BASE_STORAGE_PATH + new_filename[0])
new_filename_with_path = Photo.BASE_STORAGE_PATH + new_filename[0] + '/' + new_filename
Photo.save_original(new_filename_with_path, file_content)
img = Image.open(new_filename_with_path)
#if img.mode != "RBG":
# img = img.convert("RGB")
maps_image = Photo.resize(img, Photo.MAPS_THUMBNAIL, new_filename, 'maps_')
tiny_image = Photo.resize(img, Photo.TINY_THUMBNAIL, new_filename, 'tiny_')
small_image = Photo.resize(img, Photo.SMALL_THUMBNAIL, new_filename, 'small_')
big_image = Photo.resize(img, Photo.BIG_THUMBNAIL, new_filename, 'big_')
maxi_image = Photo.resize(img, Photo.MAXI_THUMBNAIL, new_filename, 'maxi_')
photo = self.save_photo(new_filename_with_path, main=main)
return photo
示例2: save_event_photo
# 需要导入模块: from photo import Photo [as 别名]
# 或者: from photo.Photo import resize [as 别名]
def save_event_photo(cls, event_id, photo):
if type(photo) is type(''):
return False
file_content = photo.file.read()
if len(file_content) == 0:
return False
filename, ext = os.path.splitext(photo.filename)
filename = unicodedata.normalize('NFD', filename).encode('ascii', 'ignore')
md5_ = md5(str(file_content)).hexdigest()
new_filename = md5_ + '_' + filename.lower() + ext.lower()
if not os.path.exists(Photo.BASE_STORAGE_PATH + new_filename[0]):
os.makedirs(Photo.BASE_STORAGE_PATH + new_filename[0])
new_filename_with_path = Photo.BASE_STORAGE_PATH + new_filename[0] + '/' + new_filename
Photo.save_original(new_filename_with_path, file_content)
img = Image.open(new_filename_with_path)
if img.mode != "RBG":
img = img.convert("RGB")
tiny_image = Photo.resize(img, Photo.TINY_THUMBNAIL, new_filename, 'tiny_')
small_image = Photo.resize(img, Photo.SMALL_THUMBNAIL, new_filename, 'small_')
big_image = Photo.resize(img, Photo.BIG_THUMBNAIL, new_filename, 'big_')
maxi_image = Photo.resize(img, Photo.MAXI_THUMBNAIL, new_filename, 'maxi_')
photo = Photo()
photo.filepath = new_filename_with_path
photo.event_id = event_id
photo.is_main = True
DBSession.add(photo)
DBSession.flush()
return photo