I wrote an article about Image processing with ImageMagic before. This time, I would like to write about image processing using Python's PIL library.
I will use the image below (800 * 600) this time as well.
from PIL import Image
#Read an existing file
img = Image.open('testimg/bb8.jpg', 'r')
#Resize. Specify the width and height.
resize_img = img.resize((800,600))
#Save the image. Save the resized image.
resize_img.save('testimg/resize_img.jpg')
The above image to be processed this time is the one of (4032 * 3024) resized above!
rotate_img = img.rotate(45)
Now this! The end part is black when it is rotated. It's different from ImageMagic.
def canvasimage(inimg1, inimg2, outimg):
img1 = Image.open(inimg1, 'r')
img2 = Image.open(inimg2, 'r')
canvas = Image.new('RGB', (800, 1200), (255, 255, 255))
canvas.paste(img1, (0, 0))
canvas.paste(img2, (0, 600))
canvas.save(outimg, 'JPEG')
Lined! !! !!
How to prevent black from entering when rotating! Examine you.
Recommended Posts