批量调整图像大小的文件夹至两个不同的尺寸,并重命名文件ImageMagick(MAC OS)
我希望循环浏览文件夹中的许多图像,调整大小并裁剪两种不同的尺寸,然后将其重命名。我可以让一套与此代码一起使用:
for f in *.png; do convert "$f" -resize 1500x \! -gravity Center \! -extent 1500x500 \! -set filename:f "%[t]-twitter" "%[filename:f].png"
done
这给了我一个很好的尺寸图像,从中心剪下。如果我然后再次将其运行到1100px宽的裁剪,我最终会创建两个版本,因为我是根据原件创建的,并为Twitter图像进行了调整。我找不到一种将多个尺寸和重新名称的方法组合在一起,并从一个文件夹中批量运行,同时输出到同一文件夹中。有人有什么建议吗?
I'm looking to loop through a number of images in a folder, resize and crop them to two different sizes, then rename them. I can get one set to work with this code:
for f in *.png; do convert "$f" -resize 1500x \! -gravity Center \! -extent 1500x500 \! -set filename:f "%[t]-twitter" "%[filename:f].png"
done
which gives me a nice sized image, cropped from the center. If I then run this again to crop to 1100px wide I end up creating two versions as I'm creating from the originals and my resized for twitter images. I can't find a way to combine multiple resizes and re-names and run in bulk from one folder, whilst outputting into the same folder. Does anyone have any suggestions at all please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在ImageMagick中,我相信(未经测试)可以按照以下操作。如果需要,则extent将裁剪,否则它将垫板(因此您可能需要在extent之前设置 - background颜色,即使不使用它),
上述输入大小将大小为两个不同的尺寸。您可以根据需要指定尺寸。
如果要调整第一个调整大小以制作第二个大小,则将-clone 0更改为-clone 1。
In Imagemagick, you can do it as follow, I believe (untested). the -extent will crop if needed otherwise it will pad (so you may want to set the -background color before -extent, even if it is not used)
The above will resize the input to two different sizes. You can specify the sizes as you want.
If you want to resize the first resize to make the second, then change -clone 0 to -clone 1.