本文整理汇总了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")
示例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()
示例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
示例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
示例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))
示例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))
示例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