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


Python resizeimage.resize_cover方法代碼示例

本文整理匯總了Python中resizeimage.resizeimage.resize_cover方法的典型用法代碼示例。如果您正苦於以下問題:Python resizeimage.resize_cover方法的具體用法?Python resizeimage.resize_cover怎麽用?Python resizeimage.resize_cover使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在resizeimage.resizeimage的用法示例。


在下文中一共展示了resizeimage.resize_cover方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: resize_and_crop

# 需要導入模塊: from resizeimage import resizeimage [as 別名]
# 或者: from resizeimage.resizeimage import resize_cover [as 別名]
def resize_and_crop(image_address, output_address, f_widht, f_height):
    """
    Function for resizing and cropping of single image.
    The image has to be bigger than the desired size.
    If smaller in any dimension, the image will be discarded
    
    Args:
        image_address (string): Image to be resized
        output_address (string): Final destination of the resized image
        f_widht (int): Final desired widht in pixels
        f_height (int): Final desired height in pixels
        
    Returns:
        Nothing
    """
    with open(image_address, 'r+b') as f:
        with Image.open(f) as image:
            widht, height = image.size
            if(widht >= f_widht and height >= f_height):
                cover = resizeimage.resize_cover(image, [f_widht, f_height])
                cover.save(output_address, image.format)
            else:
                print("Image too small to be resized") 
開發者ID:921kiyo,項目名稱:3d-dl,代碼行數:25,代碼來源:Resize_background.py

示例2: resize

# 需要導入模塊: from resizeimage import resizeimage [as 別名]
# 或者: from resizeimage.resizeimage import resize_cover [as 別名]
def resize(path_to_image, width, height):
        """Resize the image and save it again.
        :param path_to_image: os.path
        :param width: int
        :param height: int
        :return: None
        """

        fd_img = open(path_to_image, 'rb')
        img = Image.open(fd_img)
        img = resizeimage.resize_cover(img, [int(width), int(height)])
        img.save(path_to_image, img.format)
        fd_img.close() 
開發者ID:arrrlo,項目名稱:Google-Images-Search,代碼行數:15,代碼來源:fetch_resize_save.py

示例3: _resize_image

# 需要導入模塊: from resizeimage import resizeimage [as 別名]
# 或者: from resizeimage.resizeimage import resize_cover [as 別名]
def _resize_image(self, path, output_path=None, size=[200, 200]):
        """Thumbnail max size allowed: 200x200"""

        # TODO: maybe move to someplace called utility or helper
        if not output_path:
            output_path = path
        with open(path, "rb") as f:
            with Image.open(f) as image:
                cover = resizeimage.resize_cover(image, size)
                cover.save(output_path, image.format)
        return output_path 
開發者ID:mukulhase,項目名稱:WebWhatsapp-Wrapper,代碼行數:13,代碼來源:__init__.py

示例4: _rotate_and_scale_image

# 需要導入模塊: from resizeimage import resizeimage [as 別名]
# 或者: from resizeimage.resizeimage import resize_cover [as 別名]
def _rotate_and_scale_image(self, file, image_target_width=154, image_target_height=111,
                                image_quality_factor=20, image_rotate=True, image_export=False):

        with Image.open(file) as image:
            if image_rotate and image.width < image.height:
                image = image.rotate(90, expand=True)
                logger.debug('rotating image by 90 degrees')

            if image.width < image_quality_factor * image_target_width \
                    or image.height < image_quality_factor * image_target_height:
                factor_width = math.floor(image.width / image_target_width)
                factor_height = math.floor(image.height / image_target_height)
                factor = min([factor_height, factor_width])

                logger.debug('image is smaller than default for resize/fill. '
                             'using scale factor {} instead of {}'.format(factor, image_quality_factor))
                image_quality_factor = factor

            width = image_target_width * image_quality_factor
            height = image_target_height * image_quality_factor
            logger.debug('resizing image from {}x{} to {}x{}'
                         .format(image.width, image.height, width, height))

            cover = resizeimage.resize_cover(image, [width, height], validate=True)
            with BytesIO() as f:
                cover.save(f, 'PNG')
                scaled = f.getvalue()

            if image_export:
                name = strftime("postcard_creator_export_%Y-%m-%d_%H-%M-%S.jpg", gmtime())
                path = os.path.join(os.getcwd(), name)
                logger.info('exporting image to {} (image_export=True)'.format(path))
                cover.save(path)

        return scaled


# expose Token class in this module for backwards compatibility 
開發者ID:abertschi,項目名稱:postcard_creator_wrapper,代碼行數:40,代碼來源:postcard_creator.py

示例5: test_resize_cover

# 需要導入模塊: from resizeimage import resizeimage [as 別名]
# 或者: from resizeimage.resizeimage import resize_cover [as 別名]
def test_resize_cover(self):
        """
        Test that the image resized with resize_cover
        has the expected size
        """
        with self._open_test_image() as img:
            img = resizeimage.resize_cover(img, [200, 100])
            filename = self._tmp_filename('resize-cover.jpeg')
            img.save(filename, img.format)
            with Image.open(filename) as image:
                self.assertEqual(image.size, (200, 100)) 
開發者ID:VingtCinq,項目名稱:python-resize-image,代碼行數:13,代碼來源:tests.py

示例6: test_can_not_resize_cover_larger_size

# 需要導入模塊: from resizeimage import resizeimage [as 別名]
# 或者: from resizeimage.resizeimage import resize_cover [as 別名]
def test_can_not_resize_cover_larger_size(self):
        """
        Test that resizing an image with resize_cover
        to a size larger than the original raises an error
        """
        with self._open_test_image() as img:
            with self.assertRaises(ImageSizeError):
                resizeimage.resize_cover(img, (801, 534)) 
開發者ID:VingtCinq,項目名稱:python-resize-image,代碼行數:10,代碼來源:tests.py

示例7: find_all_files

# 需要導入模塊: from resizeimage import resizeimage [as 別名]
# 或者: from resizeimage.resizeimage import resize_cover [as 別名]
def find_all_files(min_pixels, origin_folder, target_folder):
    """
    Function that searches all subfolders of given folder.
    This function assumes that all files in that folder are image files
    If this is not the case errors will occur as no check is carried out.

    For each file, it checks that both of its dimensions are bigger than 
    min_pixels. If so, it will rescale and crop the image to
    min_pixels*min_pixels and save the file to the destination given
    in the top of this file
    
    There is a testing feature count, which allows only few subfolders 
    to be searched, so that this function can be tested
    
    Args:
        min_pixels (int): The final image will be square of this number of pixels 
        origin_folder (string): Path to a folder, which will be searched for
                any images in it or any of its subdirectories
        target_folder (string): path to folder to which the resized images
                should be saved to. This folder will have flat structure.
        
    Returns: 
        root (string): Returns the root address of the original folder
    """
    #count = 0
    for root, dirs, files in os.walk(origin_folder):
        vis_files = [f for f in files if not f[0] == '.']
        copy = True
        """
        copy = False
               
        if(root.endswith("indoor")):
            print("I am indoor")
            target_folder = indoor_address
            copy = True
       
        if(root.endswith("outdoor")):
            print("I am outdoor")
            target_folder = outdoor_address
            copy = True
        """
        if(len(vis_files)>0 and copy):
            for image_name in vis_files:
                #print(root, dirs, image_name)
                with Image.open(root+"/"+ image_name) as tested_image:
                        width, height = tested_image.size
                        if(width>=min_pixels and height>= min_pixels):                        
                            cover = resizeimage.resize_cover(tested_image, [min_pixels, min_pixels])
                            cover.convert('RGB').save(target_folder+image_name, 'JPEG')
       
    return root 
開發者ID:921kiyo,項目名稱:3d-dl,代碼行數:53,代碼來源:Resize_background.py


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