首页 > 其他分享 >裁图

裁图

时间:2024-06-13 13:43:38浏览次数:4  
标签:img crop file path folder root 裁图

import os
from PIL import Image

def crop_images(root_folder):
    for root, dirs, files in os.walk(root_folder):
        for file in files:
            if file.lower().endswith(('png', 'jpg', 'jpeg', 'bmp', 'gif')):
                file_path = os.path.join(root, file)
                with Image.open(file_path) as img:
                    if img.width == 2048 and img.width < img.height:
                        left = 0
                        top = img.height - 2048
                        right = 2048
                        bottom = img.height
                        cropped_img = img.crop((left, top, right, bottom))
                        cropped_img.save(file_path)
                        print(f'Cropped {file_path}')

# 调用函数并传入顶层文件夹路径
root_folder = input("请输入顶层文件夹路径: ")
crop_images(root_folder)

 

标签:img,crop,file,path,folder,root,裁图
From: https://www.cnblogs.com/zly324/p/18245716

相关文章

  • 通过拍照或选择本地图片并剪裁图片设置成头像
    还是直接上代码importjava.io.File;importandroid.app.AlertDialog;importandroid.content.Context;importandroid.content.DialogInterface;importandroid.content.Intent;importandroid.graphics.Bitmap;importandroid.graphics.drawable.B......
  • Basler相机分辨率降低设置(不是裁图)
    宽高设置,其实是裁图。那么如何保持视野不变,降低分辨率呢?支持Binning功能(像素合并)的相机才能降低分辨率。目前手头的黑白相机支持,彩色相机不支持。黑白型号 acA3088-57um......