[英]Command Line String Checking and argument passing (ImageMagick)
I have this cool little snippet that I found, which adds a shadow to an image. 我发现了这个很酷的小片段,为图像添加了阴影。 (using imageMagick, i think..)
(我认为使用imageMagick。)
image-shadow () {
out=${1%.*}-shadow.${1#*.}
in=$1
echo "Converted file : $out"
if [ ! -z $2 ] ; then
convert $in -frame $2 $out
in=$out
fi
convert $in \( +clone -background black -shadow 60x5+3+3 \) \
+swap -background transparent -layers merge +repage $out
}
We use: 我们用:
image-shadow test.png 0x0
to add 0x0 border, and 3x3 shadow, as defined inside the function... 根据功能内部定义添加0x0边框和3x3阴影...
Now, I have *-hd.png images, and *.png images .. And would like to add 3x3 shadows to the *.png and 6x6 to the *-hd.png (obviously, retina graphics..) 现在,我有* -hd.png图像和* .png图像..并想在* .png中添加3x3阴影,在* -hd.png中添加6x6(显然是视网膜图形..)
1- How can I compare the the image name, and decide 1-如何比较图像名称,并确定
2- How can I pass the shadow size 2-如何传递阴影大小
Thanks! 谢谢!
For 1.: Use find, it is really the Swiss army knife for such jobs: 对于1 ::使用find,实际上是用于此类工作的瑞士军刀:
find '(' -name '*.png' -and -not -name '*-hd.png' ')' -exec image-shadow '{}' 0x0 ';'
Of course, you'll have to save your function as a single shell file instead of a shell function, but this is desirable for code reuse anyway. 当然,您必须将函数保存为单个shell文件而不是shell函数,但是无论如何,这对于代码重用来说是理想的。
For 2.: Use another command line argument, which is referenced in the function as $3. 对于2 ::使用另一个命令行参数,该参数在函数中被引用为$ 3。
for f in *.png; do
case "$f" in
*-hd.png) shadow="6x6" ;;
*) shadow="3x3" ;;
esac
image-shadow "$f" $shadow
dona
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.