如何使用批量转换命令,一次干净的正则表达式扫描?

发布于 2025-01-01 04:11:22 字数 251 浏览 1 评论 0原文

我有一堆像 PHO_123456_12345678.jpg 的图像,我想生成名为 THUMB90_123456_12345678.jpg 的新图像,这是我想使用的命令,但我不知道如何批量执行此操作。

convert SRC.JPG      -resize 90x90^ \ -gravity center -extent 90x90  DST.JPG

有没有办法用正则表达式来做到这一点,还是必须是 shell 脚本?

I have a bunch of images that loo like PHO_123456_12345678.jpg and I want to generate new images called THUMB90_123456_12345678.jpg, this is the command I want to use except I don't know how to do this in bulk.

convert SRC.JPG      -resize 90x90^ \ -gravity center -extent 90x90  DST.JPG

Is there a way to do it with regular expressions or does it have to be a shell script?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

下壹個目標 2025-01-08 04:11:23

让我们看看...我认为这应该有效:

ls *.jpg | sed -i -e "s~^PHO_~~" | xargs -n1 -i convert PHO_{} -resize 90x90^ \ -gravity center -extent 90x90 THUMB90_{}

Let's see... I think this should work:

ls *.jpg | sed -i -e "s~^PHO_~~" | xargs -n1 -i convert PHO_{} -resize 90x90^ \ -gravity center -extent 90x90 THUMB90_{}
樱娆 2025-01-08 04:11:23

它必须是 shell 脚本内正则表达式的组合。

IMGPREFIX='PHO'
THUMBPREFIX='THUMB90'

for filename in $IMGPREFIX_*.jpg ; do
  thumbfilename=$(echo $filename | sed 's/$IMGPREFIX_\(.*\)\.jpg/$THUMBPREFIX_\1\.jpg/')
  convert $filename -resize 90x90^ \ -gravity center -extent 90x90  $thumbfilename
done

It would have to be a combination of a regular expression [inside] a shell script.

IMGPREFIX='PHO'
THUMBPREFIX='THUMB90'

for filename in $IMGPREFIX_*.jpg ; do
  thumbfilename=$(echo $filename | sed 's/$IMGPREFIX_\(.*\)\.jpg/$THUMBPREFIX_\1\.jpg/')
  convert $filename -resize 90x90^ \ -gravity center -extent 90x90  $thumbfilename
done
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文