當前位置: 首頁>>代碼示例>>Python>>正文


Python Photo.resize方法代碼示例

本文整理匯總了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
開發者ID:paweldudzinski,項目名稱:foodel,代碼行數:35,代碼來源:product.py

示例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
開發者ID:paweldudzinski,項目名稱:foodel,代碼行數:39,代碼來源:event.py


注:本文中的photo.Photo.resize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。