添加水印,然后保存图片
(imagePath, mark, args)
| 46 | |
| 47 | |
| 48 | def add_mark(imagePath, mark, args): |
| 49 | """ |
| 50 | 添加水印,然后保存图片 |
| 51 | """ |
| 52 | im = Image.open(imagePath) |
| 53 | im = ImageOps.exif_transpose(im) |
| 54 | |
| 55 | image, mask = mark(im) |
| 56 | name = os.path.basename(imagePath) |
| 57 | if image: |
| 58 | if not os.path.exists(args.out): |
| 59 | os.mkdir(args.out) |
| 60 | |
| 61 | new_name = os.path.join(args.out, name) |
| 62 | if os.path.splitext(new_name)[1] != '.png': |
| 63 | image = image.convert('RGB') |
| 64 | image.save(new_name, quality=args.quality) |
| 65 | #mask.save(os.path.join(args.out, os.path.basename(os.path.splitext(new_name)[0]) + '.png'), |
| 66 | # quality=args.quality) |
| 67 | print(name + " Success.") |
| 68 | else: |
| 69 | print(name + " Failed.") |
| 70 | |
| 71 | |
| 72 | def set_opacity(im, opacity): |