Skip to content

Instantly share code, notes, and snippets.

@thieu1995
Last active February 5, 2025 15:46
Show Gist options
  • Save thieu1995/028f2597bd9b86804b239d8fcf1dfb5e to your computer and use it in GitHub Desktop.
Save thieu1995/028f2597bd9b86804b239d8fcf1dfb5e to your computer and use it in GitHub Desktop.
How to make passport avatar to submit on online website (dichvucong.gov.vn)
# 1st: Take a photo with portray image.
# 2nd: Use this website to make passport photo: https://www.cutout.pro/passport-photo-maker/upload
# 3nd: Download the transformation image above and run this code:
from PIL import Image
# Đường dẫn ảnh
input_image_path = "your_transformed_image.jpg" # Thay bằng đường dẫn ảnh gốc
output_image_path = "the_final_image_to_submit.jpg"
# Mở ảnh
image = Image.open(input_image_path)
# Kích thước mong muốn (cm)
width_cm, height_cm = 4, 6
dpi = 600 # Bạn có thể đặt giá trị cao hơn nếu muốn
# Chuyển đổi kích thước từ cm sang pixel
width_px = int(width_cm * dpi / 2.54)
height_px = int(height_cm * dpi / 2.54)
# Thay đổi kích thước ảnh
image_resized = image.resize((width_px, height_px), Image.LANCZOS)
# Lưu ảnh với DPI mong muốn
image_resized.save(output_image_path, dpi=(dpi, dpi))
print(f"Ảnh đã được lưu với kích thước {width_cm}x{height_cm} cm và DPI {dpi}.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment