added batch image watermarker (#184)

* added batch image watermarker

* Create README.md

* Update README.md to include project
This commit is contained in:
Remco Halman 2020-10-09 10:24:35 +02:00 committed by GitHub
parent 11501c5292
commit 80bfc6c98d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 0 deletions

View File

@ -156,6 +156,8 @@ So far, the following projects have been integrated to this repo:
|[Codeforces Checker](codeforcesChecker)|[Jinesh Parakh](https://github.com/jineshparakh)|
|[Github repo creator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Git_repo_creator)|[Harish Tiwari ](https://github.com/optimist2309)
|[Remove-Duplicate-Files](Remove-Duplicate-Files)|[Aayushi Varma](https://github.com/aayuv17)
|[Image Watermarker (batch)](Image Watermarker (batch))|[Remco Halman](https://github.com/remcohalman)
## How to use :

View File

@ -0,0 +1,13 @@
## Python script to watermark your images
in the `main.py` file edit the following items:
```bash
"<input folder>",
"<output folder>",
"<watermark image>"
```
using the input folder path to loop over all images and output them to outputfolder.
Best practise is to use a image with transparent background.

48
imageWatermarker/main.py Normal file
View File

@ -0,0 +1,48 @@
import os
import sys
from os.path import join
from PIL import Image, ImageEnhance
def FolderSelectAndRun():
batch(
"<input folder>",
"<output folder>",
"<watermark image>"
)
basewidth = 2048
def batch(infolder, outfolder, watermark):
mark = Image.open(watermark)
count = 0
for root, dirs, files in os.walk(infolder):
for name in files:
try:
count += 1
im = Image.open(join(root, name))
# New image in the making
layer = Image.new('RGBA', im.size, (0, 0, 0, 0))
position = (im.size[0] - (mark.size[0] + 50),
im.size[1] - (mark.size[1] + 50))
layer.paste(mark, position)
new_image = Image.composite(layer, im, layer)
# Resize in perspective
wpercent = (basewidth / float(im.size[0]))
hsize = int((float(new_image.size[1]) * float(wpercent)))
smaller_new_image = new_image.resize(
(basewidth, hsize), Image.ANTIALIAS)
# Save new smaller image
smaller_new_image.save(
join(outfolder, ('with-watermark_' + name)), 'jpeg')
except Exception as error:
# Debug line while making changes
print('Caught this error: ' + repr(error))
if __name__ == '__main__':
FolderSelectAndRun()

View File

@ -0,0 +1 @@
Pillow==7.2.0