Created
October 10, 2019 10:33
-
-
Save imaginabit/0b63b072790efa2584b84d18c1e6510a to your computer and use it in GitHub Desktop.
take all the images in curret dir and subdirs and copy to targetdir with a watermark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
import pathlib | |
myCmd = 'convert %s mark.gif +distort affine "0,0 0,0 %[w],%[h] %[fx:t?v.w*(u.h/v.h*0.9):s.w],%[fx:t?v.h*(u.h/v.h*0.9):s.h]" -shave 1 -gravity center -compose dissolve -define compose:args=\'40\' -composite ~/mark/%s' | |
targetDir = '/home/fer/mark' | |
watermark = '~/mark.gif' | |
filepath = 'imagelist.txt' | |
with open(filepath) as fp: | |
line = fp.readline() | |
cnt = 1 | |
while line: | |
print("Line {}: {}".format(cnt, line.strip())) | |
filename = line.strip() | |
directory = line[1:line.rindex('/')] | |
directory = targetDir+directory | |
#print (directory) | |
if not os.path.exists(directory): | |
print("create dir %s" % directory) | |
pathlib.Path(directory).mkdir(parents=True) | |
os.system( 'touch %s%s' % ( directory, line[line.rindex('/'):] ) ) | |
else: | |
print("ok dir %s" % directory) | |
os.system( 'touch %s%s' % ( directory, line[line.rindex('/'):] ) ) | |
img = '%s%s' % (targetDir,line[1:].strip()) | |
myCmd = 'convert %s %s ' % ( line.strip(), watermark) | |
myCmd += r'+distort affine "0,0 0,0 %[w],%[h] %[fx:t?v.w*(u.h/v.h*0.3):s.w],%[fx:t?v.h*(u.h/v.h*0.3):s.h]" ' | |
myCmd += '-shave 1 -gravity center -compose dissolve -define compose:args=\'30\' -composite %s' % img | |
os.system(myCmd) | |
txtCmd = 'convert %s -gravity South -pointsize 20 -fill "rgba(255,255,255,0.5)" -annotate +0+30 \'myurl.com\' %s ' % (img,img) | |
print ( txtCmd ) | |
os.system( txtCmd ) | |
#exit() | |
line = fp.readline() | |
cnt = cnt + 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment