resize image with python code example
Example 1: python pil resize image
from PIL import Image
# Image.open() can also open other image types
img = Image.open("some_random_image.jpg")
# WIDTH and HEIGHT are integers
resized_img = img.resize((WIDTH, HEIGHT))
resized_img.save("resized_image.jpg")
Example 2: python resize image
from PIL import Image
image = Image.open("path/.../image.png")
image = image.resize((500,500),Image.ANTIALIAS)
image.save(fp="newimage.png")
Example 3: pyhton image resize
from PIL import Image
from resizeimage import resizeimage
fd_img = open('test-image.jpeg', 'r')
img = Image.open(fd_img)
img = resizeimage.resize_cover(img, [200, 100])
img.save('test-image-cover.jpeg', img.format)
fd_img.close()
Example 4: pil resize image
im = Image.open('image.jpg')
im = im.resize((w, h))
Example 5: pyhton image resize
from PIL import Image
from resizeimage import resizeimage
with open('test-image.jpeg', 'r+b') as f:
with Image.open(f) as image:
cover = resizeimage.resize_cover(image, [200, 100])
cover.save('test-image-cover.jpeg', image.format)
Example 6: pyhton image resize
from PIL import Image
from resizeimage import resizeimage
with open('test-image.jpeg', 'r+b')
with Image.open() as image:
is_valid = resizeimage.resize_cover.validate(image, [200, 100])
# do something else...
if is_valid:
with Image.open('test-image.jpeg') as image:
resizeimage.resize_cover.validate(image, [200, 100], validate=False)
cover = resizeimage.resize_cover(image, [200, 100])
cover.save('test-image-cover.jpeg', image.format)