├── Fuu_ImgProcess.py ├── README.md ├── runsplit.bat ├── 关键字整理.xlsx └── 自动发指令,下图脚本.Q /Fuu_ImgProcess.py: -------------------------------------------------------------------------------- 1 | import os 2 | import filecmp 3 | from pathlib import Path 4 | from PIL import Image, ImageDraw, ImageFont 5 | 6 | 7 | def remove_duplicate_files(folder_path): 8 | folder = Path(folder_path) 9 | if not folder.is_dir(): 10 | print("Invalid folder path.") 11 | return 12 | 13 | file_list = list(folder.glob('*')) # 获取文件夹中的所有文件 14 | 15 | for i in range(len(file_list)): 16 | file1 = file_list[i] 17 | if not file1.exists(): 18 | continue 19 | 20 | for j in range(i + 1, len(file_list)): 21 | file2 = file_list[j] 22 | if not file2.exists(): 23 | continue 24 | 25 | if filecmp.cmp(file1, file2, shallow=False): # 如果文件内容相同 26 | print(f"Duplicate files found: {file1} and {file2}") 27 | file2.unlink() # 删除其中一个文件 28 | print(f"Removed {file2}") 29 | 30 | 31 | 32 | 33 | 34 | def split_image(image_path, output_folder): 35 | # 将图片十字4分的函数,分割好的图片输出到output 36 | # 需要注意的是,在做分割前需要给图片重命名 37 | img = Image.open(image_path) 38 | img_name = os.path.splitext(os.path.basename(image_path))[0] 39 | width, height = img.size 40 | half_width = width // 2 41 | half_height = height // 2 42 | img1 = img.crop((0, 0, half_width, half_height)) 43 | img2 = img.crop((half_width, 0, width, half_height)) 44 | img3 = img.crop((0, half_height, half_width, height)) 45 | img4 = img.crop((half_width, half_height, width, height)) 46 | img1.save(os.path.join(output_folder, f"{img_name}_1.png")) 47 | img2.save(os.path.join(output_folder, f"{img_name}_2.png")) 48 | img3.save(os.path.join(output_folder, f"{img_name}_3.png")) 49 | img4.save(os.path.join(output_folder, f"{img_name}_4.png")) 50 | 51 | 52 | def process_splitimages(input_folder, output_folder): 53 | # 将Input中的文件分割并将结果输出到output 54 | if not os.path.exists(output_folder): 55 | os.makedirs(output_folder) 56 | 57 | for file in os.listdir(input_folder): 58 | if file.lower().endswith(('.png', '.jpg', '.jpeg')): 59 | image_path = os.path.join(input_folder, file) 60 | split_image(image_path, output_folder) 61 | 62 | 63 | def add_watermark(input_image_path, output_image_path, watermark_text): 64 | # 打开原始图片 65 | base_image = Image.open(input_image_path).convert("RGBA") 66 | # 创建一个与原图大小相同的透明图片 67 | txt = Image.new("RGBA", base_image.size, (255, 255, 255, 0)) 68 | # 获取字体 69 | #font = ImageFont.truetype("arial.ttf", int(base_image.size[1] * 0.1)) 70 | font = ImageFont.truetype("./VonwaonBitmap.ttf", int(base_image.size[1] * 0.1)) 71 | # 初始化画布 72 | d = ImageDraw.Draw(txt) 73 | # 计算文字位置 74 | text_size = d.textsize(watermark_text, font) 75 | text_position = (int((base_image.size[0] - text_size[0]) / 2), int((base_image.size[1] - text_size[1]) / 2)) 76 | # 将水印文字绘制到透明图片上 77 | d.text(text_position, watermark_text, font=font, fill=(255, 255, 255, 128)) 78 | # 将两张图片合并 79 | watermarked = Image.alpha_composite(base_image, txt) 80 | # 保存添加水印后的图片 81 | watermarked.convert("RGB").save(output_image_path) 82 | 83 | def process_watermarkImgs(watermark_text ,input_folder ,output_folder ): 84 | if not os.path.exists(output_folder): 85 | os.makedirs(output_folder) 86 | for image_name in os.listdir(input_folder): 87 | input_image_path = os.path.join(input_folder, image_name) 88 | output_image_path = os.path.join(output_folder, image_name) 89 | add_watermark(input_image_path, output_image_path, watermark_text) 90 | 91 | if __name__ == "__main__": 92 | OriginImgs = "./OriginImgs" 93 | SplitedImgs = "./SplitedImgs" 94 | WateredImgs = "./WateredImgs" 95 | WaterMarkText = "挖煤医生,向你问好!" 96 | 97 | print("批量图片处理工具 V1.0 by 挖煤医生@bilibili") 98 | print("请确保你的python环境已安装以下类库: pillow, rembg") 99 | print("默认原图文件夹(四格图):OriginImgs \n 默认分割文件夹(单图):SplitedImgs \n 默认水印文件夹:WateredImgs") 100 | print("默认水印文本:挖煤医生,向你问好") 101 | remove_duplicate_files(OriginImgs) 102 | process_splitimages(OriginImgs, SplitedImgs) 103 | process_watermarkImgs(WaterMarkText, SplitedImgs, WateredImgs ) 104 | pass -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AutoMJ 2 | ## 功能简介: 3 | 自动化的提交imagine prompt,自动化下载接收到的图片;自动化将四宫格图片去重,拆分,分类,加水印 4 | 5 | 2323.04.06: 上传了按键精灵版本的自动发消息脚本:使用前需要根据你的电脑环境做点儿调试(重新截个图,调整一下找图准确度之类的) 6 | 正在录一个完整的操作视频,大概4.6晚上上传 挖煤医生@bilibili; 7 | 感谢大家的关注,欢迎Pull requests~ 8 | 9 | 10 | 完整的操作视频已经上传:https://www.bilibili.com/video/BV12k4y1v7Eh/ 11 | 感谢大家的支持~ 12 | 13 | 14 | I am a really bad programmer. This was made over the course of 32 hours on no sleep and only a pack of sour skittles to keep me awake. It's unoptomised, buggy, and liable to cause headache inducing problems because I didn't make a proper visualizer and also didn't comment pretty much anything. If you can stomach all that, then it's pretty easy to use 15 | -------------------------------------------------------------------------------- /runsplit.bat: -------------------------------------------------------------------------------- 1 | python ./Fuu_ImgProcess.py -------------------------------------------------------------------------------- /关键字整理.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DocMine/AutoMJ/4730cf8113ab8a35d134afe5a25fd2ad89aff8c6/关键字整理.xlsx -------------------------------------------------------------------------------- /自动发指令,下图脚本.Q: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DocMine/AutoMJ/4730cf8113ab8a35d134afe5a25fd2ad89aff8c6/自动发指令,下图脚本.Q --------------------------------------------------------------------------------