天宫鹤

Python按身份证实际大小调整图片尺寸

# 按身份证实际大小调整图片尺寸
def resize_image_by_id(image, width_mm=86, height_mm=55):
    # 四周裁掉5mm
    # image = crop_image_by_border(image, 5, 5, 5, 5)  # 四周裁掉5mm

    # 计算新的宽度和高度(像素单位)
    new_width = int(width_mm / inch_to_mm * dpi)
    new_height = int(height_mm / inch_to_mm * dpi)
    # 创建新的图片并调整大小
    image = image.resize((new_width, new_height), Image.Resampling.LANCZOS)

    return image

 

posted on 2024-07-06 17:09  GoGrid  阅读(3)  评论(0编辑  收藏  举报

导航