在 Imagemagick for linux 中如何对目录进行批量转换

发布于 2024-09-15 06:54:10 字数 607 浏览 1 评论 0原文

我希望能够指定扫描位置和转换后文件的位置。

只是有很多转换,我有一个脚本可以为我进行排序。 目前我已经尝试过

convert -resize 300x300 >  /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/normal/*.jpg /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/tn_med/$1.jpg

并且

for i in $( ls /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/normal); do  /usr/convert resize 360x360 > /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/normal/$i  /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/tn_med/$i done;

I want to be able to specify the location in both where to scan and where the converted file will go.

It's just there is a lot of conversions and I've got a script which should sort it for me.
Currently I've tried

convert -resize 300x300 >  /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/normal/*.jpg /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/tn_med/$1.jpg

and

for i in $( ls /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/normal); do  /usr/convert resize 360x360 > /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/normal/$i  /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/tn_med/$i done;

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

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

发布评论

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

评论(3

憧憬巴黎街头的黎明 2024-09-22 06:54:10
for i in $( ls /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/normal); do
    convert -resize 360x360 /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/normal/$i  /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/tn_med/$i;
done

知道了!

for i in $( ls /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/normal); do
    convert -resize 360x360 /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/normal/$i  /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/tn_med/$i;
done

got it!

执手闯天涯 2024-09-22 06:54:10

正如评论所建议的,您可以使用 find 命令:

outdir=/media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/tn_med
cd /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/normal
find . -iname '*.jpg' -print0 | xargs -I{} -0 -r convert -resize 300x300 {} $outdir/{}

通过使用 -print0 和 xarg 的 -0 选项,这还可以处理带有空格和其他内容的文件名奇怪的字符。

As comments suggested, you can use the find command:

outdir=/media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/tn_med
cd /media/usbdisk1/development/ephoto/richard/images/gallery/2007/29/normal
find . -iname '*.jpg' -print0 | xargs -I{} -0 -r convert -resize 300x300 {} $outdir/{}

By using -print0 and xarg's -0 option, this also handles filenames with spaces and other odd characters.

青衫儰鉨ミ守葔 2024-09-22 06:54:10

没有理由将长目录重复三遍。使用变量作为基数。并且不要使用 ls

base="/media/usbdisk1/development/ephoto/richard/images/gallery/2007/29"
for file in "$base/normal/*"
do
    convert -resize 360x360 "$file" "$base/tn_med/$(basename $file)"
done

您可以这样做,而不是 basename

    convert -resize 360x360 "$file" "$base/tn_med/${file##*/}"

There's no reason to repeat your long directory three times. Use a variable for the base. And don't use ls:

base="/media/usbdisk1/development/ephoto/richard/images/gallery/2007/29"
for file in "$base/normal/*"
do
    convert -resize 360x360 "$file" "$base/tn_med/$(basename $file)"
done

Instead of basename you could do it this way:

    convert -resize 360x360 "$file" "$base/tn_med/${file##*/}"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文