[PYTHON] Image processing with PIL (Pillow)

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. resize_img.jpg

Image size adjustment

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!

rotation

rotate_img = img.rotate(45)

rotate_img.jpg

Now this! The end part is black when it is rotated. It's different from ImageMagic.

Side by side two images

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! !! !!

canvas_img.jpg

Question

How to prevent black from entering when rotating! Examine you.

Recommended Posts

Image processing with PIL (Pillow)
Image Processing with PIL
Image processing with MyHDL
Image processing with Python
Easy image processing in Python with Pillow
Fastly replace image colors with PIL / Pillow
Image processing with Python (Part 2)
Image processing with Python (Part 1)
Image processing with Python (Part 3)
Image processing by python (Pillow)
[Python] Image processing with scikit-image
Real-time image processing basics with opencv
Image processing with Python 100 knocks # 3 Binarization
Image processing with Python 100 knocks # 2 Grayscale
Basics of binarized image processing with Python
Image processing with Python 100 knock # 10 median filter
python image processing
Create an image processing viewer with PySimpleGUI
Create a dummy image with Python + PIL.
Image processing with Python 100 knocks # 8 Max pooling
Generate many single-character images with Pillow (PIL)
Use PIL and Pillow with Cygwin Python
Image processing with Python & OpenCV [Tone Curve]
Image processing with Python 100 knock # 12 motion filter
I tried playing with the image with Pillow
Drawing with Matrix-Reinventor of Python Image Processing-
Image processing 100 knocks ①
Image processing with Python 100 knocks # 7 Average pooling
Light image processing with Python x OpenCV
Image processing with Lambda + OpenCV (gray image creation)
Image processing with Python 100 knocks # 9 Gaussian filter
XavierNX accelerates OpenCV image processing with GPU (CUDA)
Image processing from scratch with python (5) Fourier transform
Create an image composition app with Flask + Pillow
Image processing from scratch with python (4) Contour extraction
Image Processing with Python Environment Setup for Windows
I tried simple image processing with Google Colaboratory.
PIL / Pillow cheat sheet
Processing datasets with pandas (1)
Processing datasets with pandas (2)
Flat Field image processing
Image recognition with keras
First Python image processing
Read digital image processing
Parallel processing with multiprocessing
Notes on HDR and RAW image processing with Python
Image download with Flickr API
100 Language Processing with Python Knock 2015
opencv-python Introduction to image processing
Read image coordinates with Python-matplotlib
Parallel processing with local functions
"Apple processing" with OpenCV3 + Python3
Image editing with python OpenCV
Acoustic signal processing with Python (2)
Digital image processing (spatial filtering)
100 image processing knocks !! (011 --020) Early game
Acoustic signal processing with Python
Image upload & customization with django-ckeditor
Sorting image files with Python (2)
Convert color space from RGB to CIELAB with PIL (Pillow)
Sorting image files with Python (3)