当前位置: 首页>>代码示例>>Python>>正文


Python Photo.save_original方法代码示例

本文整理汇总了Python中photo.Photo.save_original方法的典型用法代码示例。如果您正苦于以下问题:Python Photo.save_original方法的具体用法?Python Photo.save_original怎么用?Python Photo.save_original使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在photo.Photo的用法示例。


在下文中一共展示了Photo.save_original方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: save_product_photo

# 需要导入模块: from photo import Photo [as 别名]
# 或者: from photo.Photo import save_original [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
开发者ID:paweldudzinski,项目名称:foodel,代码行数:35,代码来源:product.py

示例2: save_event_photo

# 需要导入模块: from photo import Photo [as 别名]
# 或者: from photo.Photo import save_original [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
开发者ID:paweldudzinski,项目名称:foodel,代码行数:39,代码来源:event.py


注:本文中的photo.Photo.save_original方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。