我有一个脚本,用图像标记我的图像。我已经将我的脚本设置为bash作业,但它始终为每一张图片打水印。我希望排除已经有水印的图片,但我没有选择将我所有的水印图片移出某个文件夹。文件夹A包含原始图像。脚本扫描文件夹A中的png、jpg和gif图像,并对它们进行水印标记,然后将原始图片移动到子文件夹。每次我的脚本扫描文件夹A时,它都会对所有已经被水印的文件进行水印。我也不能更改文件的名字。是否有一种方法可以通过将水印文件添加到文件数据库或其他方面来检查它们?我的脚本如下:
#!/bin/bash
savedir=".originals"
for image in *png *jpg *gif do if [ -s $image ] ; then # non-zero
file size
width=$(identify -format %w $image)
convert -background '#0008' -fill white -gravity center \
-size ${width}x30 caption:'watermark' \
$image +swap -gravity south -composite new-$image
mv -f $image $savedir
mv -f new-$image $image
echo "watermarked $image successfully" fi done
发布于 2015-08-09 21:07:11
下面是关于如何修改/更新当前脚本以添加一种本地数据库文件以跟踪处理过的文件的示例:
#!/bin/bash
savedir=".originals"
PROCESSED_FILES=.processed
# This would create the file for the first time if it
# doesn't exists, thus avoiding "file not found problems"
touch "$PROCESSED_FILES"
for image in *png *jpg *gif; do
# non-zero
if [ -s $image ]; then
# Grep the file from the database
grep "$image" "$PROCESSED_FILES"
# Check the result of the previous command ($? is a built-in bash variable
# that gives you that), in this case if the result from grep is different
# than 0, then the file haven't been processed yet
if [ $? -ne 0 ]; then
# Process/watermark the file...
width=$(identify -format %w $image)
convert -background '#0008' -fill white -gravity center -size ${width}x30 caption:'watermark' $image +swap -gravity south -composite new-$image
mv -f $image $savedir
mv -f new-$image $image
echo "watermarked $image successfully"
# Append the file name to the list of processed files
echo "$image" >> "$PROCESSED_FILES"
fi
fi
done
发布于 2015-08-09 21:38:26
就我个人而言,我不希望需要其他的外部数据库中的图像名称,如果该文件与图像分离,如果它们被移到不同的文件夹层次结构中,或者被重命名,该怎么办?
我的首选是在图像中设置一个注释,将每个图像标识为水印,或者没有--然后信息随图像四处传播。因此,如果我水印一个图像,我将它设置在注释中这样说。
convert image.jpg -set comment "Watermarked" image.[jpg|gif|png]
然后,在我水印之前,我可以检查ImageMagick的identify
,看看它是否完成了:
identify -verbose image.jpg | grep "comment:"
Watermarked
显然,您可以稍微复杂一点,提取当前的注释并添加“水印”部分,而不覆盖可能已经存在的任何内容。或者,您可以在对图像进行水印时设置IPTC作者/版权持有人或版权信息,并将其用作图像是否有水印的标记。
https://stackoverflow.com/questions/31908695
复制相似问题