[파이썬] imageio 워터마크 삽입
In this blog post, we will explore how to add a watermark to images using the imageio
library in Python. Watermarking images is a common practice to protect the copyright of images or to add branding elements to them.
Installing imageio
In order to use imageio
library, you need to install it first. You can install it using pip:
pip install imageio
Adding Watermark
To add a watermark to an image, you need to follow these steps:
- Import the necessary libraries:
import imageio
import numpy as np
from PIL import Image
- Load the image and the watermark image:
image = imageio.imread('input_image.jpg')
watermark = imageio.imread('watermark_image.png')
- Convert the watermark image to grayscale:
gray_watermark = np.dot(watermark[..., :3], [0.2989, 0.5870, 0.1140])
- Set the position where you want to place the watermark:
x_position = image.shape[1] - gray_watermark.shape[1] - 10
y_position = image.shape[0] - gray_watermark.shape[0] - 10
- Add the watermark to the image:
image[y_position:image.shape[0]-10, x_position:image.shape[1]-10] += gray_watermark
- Save the image with the watermark:
output_image = Image.fromarray(image)
output_image.save('output_image.jpg')
That’s it! By following these simple steps, you can easily add a watermark to your images using imageio
library in Python.
Conclusion
In this blog post, we have learned how to add a watermark to images using the imageio
library in Python. Watermarking images can help protect your copyright and add branding elements to your images. Hope you find this tutorial helpful!