I have done a bit of digging and i havn't been able to find any feasible way of adding watermarks to my 1000+ images automatically. Is this possible with irfanview?? What im looking for is just some basic transparent text overlaying across each image. Can this be done using command line? Is it possible to go one step further and add a logo watermark?
Can you recommend any other programs rather than irfanview to do t开发者_StackOverflow社区his, if its not possible to do it in this program.
I recommend using ImageMagick, which is open source and quite standard for manipulating images on the command line.
Watermarking with an image is as simple as
composite -dissolve 30% -gravity south watermark.jpg input-file.jpg output-file.jpg
With text, it's a little more complicated but possible.
Using the above command as an example, a Bash command for doing this to all files in folder would be:
for pic in *.jpg; do
composite -dissolve 30% -gravity south watermark.jpg $pic ${pic//.jpg}-marked.jpg
done
For more information about watermarking with ImageMagick, see ImageMagick v6 Examples.
Here's a quick python script based on the ImageMagik suggestion.
#!/usr/bin/env python
# encoding: utf-8
import os
import argparse
def main():
parser = argparse.ArgumentParser(description='Add watermarks to images in path')
parser.add_argument('--root', help='Root path for images', required=True, type=str)
parser.add_argument('--watermark', help='Path to watermark image', required=True, type=str)
parser.add_argument('--name', help='Name addition for watermark', default="-watermark", type=str)
parser.add_argument('--extension', help='Image extensions to look for', default=".jpg", type=str)
parser.add_argument('--exclude', help='Path content to exclude', type=str)
args = parser.parse_args()
files_processed = 0
files_watermarked = 0
for dirName, subdirList, fileList in os.walk(args.root):
if args.exclude is not None and args.exclude in dirName:
continue
#print('Walking directory: %s' % dirName)
for fname in fileList:
files_processed += 1
#print(' Processing %s' % os.path.join(dirName, fname))
if args.extension in fname and args.watermark not in fname and args.name not in fname:
ext = '.'.join(os.path.basename(fname).split('.')[1:])
orig = os.path.join(dirName, fname)
new_name = os.path.join(dirName, '%s.%s' % (os.path.basename(fname).split('.')[0] + args.name, ext))
if not os.path.exists(new_name):
files_watermarked += 1
print(' Convert %s to %s' % (orig, new_name))
os.system('composite -dissolve 30%% -gravity SouthEast %s "%s" "%s"' % (args.watermark, orig, new_name))
print("Files Processed: %s" % "{:,}".format(files_processed))
print("Files Watermarked: %s" % "{:,}".format(files_watermarked))
if __name__ == '__main__':
main()
Run it like this:
./add_watermarks.py --root . --watermark copyright.jpg --exclude marketplace
To create the watermark I just created the text in a Word document then did a screen shot of the small area of the text to end up with a copyright.jpg file.
精彩评论