In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use Python to make beautiful ID photos. The introduction in this article is very detailed and has certain reference value. Interested friends must read it!
For information only Learn to use Introduction
We mainly have two jobs to make ID photos: modify the photo background and modify the photo size. To modify the background, we need to use the third-party library removegg. To modify the photo size, we need to use the PIL library. The installation of these two libraries can be done by pip install removegg and pip install Pillow.
When using removebb, we also need an API key, which can be obtained by: First, we open the link address https://accounts.kaleido.ai/users/sign_up to register an account, and after opening it, it is shown as follows:
We fill in the email and password and then check the consent agreement and submit it. After that, the website will send a verification message to the email we just filled in. We enter our email and click the verification link to complete the verification. After that, we complete the account registration work.
After the account is registered, we then open the https://www.remove.bg/zh/profile#api-key address to log in to our account and enter the position below:
We click on the display button in the image above to get the secret key.
code implementation
The code implementation is also relatively simple, or we said before the idea: use removebb library to modify the background color of photos, use PIL library to modify the size of photos, the specific implementation is as follows:
from PIL import Image
from removebg import RemoveBg
#Change the background color of photos
def change_bgcolor(file_in, file_out, api_key, color):
rmbg = RemoveBg(api_key, 'error.log')
rmbg.remove_background_from_img_file(file_in)
no_bg_image = Image.open(file_in)
x, y = no_bg_image.size
new_image = Image.new('RGBA', no_bg_image.size, color=color)
new_image.paste(no_bg_image, (0, 0, x, y), no_bg_image)
new_image.save(file_out)
#Change photo size
def change_size(file_in, file_out, width, height):
image = Image.open(file_in)
resized_image = image.resize((width, height), Image.ANTIALIAS)
resized_image.save(file_out)
The above is all the content of this article "How to use Python to make beautiful ID photos", thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.