我需要将文件夹和子文件夹中的所有图片转换为jpg格式。我需要用命令文件批处理此过程,GUI工具对我来说是无关紧要的,我需要脚本。
我尝试使用ImageMagick中的mogrify.exe,还有convert.exe功能,但据我所知,它们都能够转换图像。
我编写了下面的脚本:
我找到了下面的代码:
我尝试使用ImageMagick中的mogrify.exe,还有convert.exe功能,但据我所知,它们都能够转换图像。
我编写了下面的脚本:
$rootdir = "E:\Apps\скрипты\temp1\graphics"
$files = dir -r -i *.png $rootdir
foreach ($file in $files) {.\mogrify.exe -format png *jpg $file}
但是它无法正常工作,当我尝试运行它时,出现了错误:
mogrify.exe: unable to open file `*jpg' @ error/png.c/ReadPNGImage/3633.
mogrify.exe: Improper image header `E:\Apps\скрипты\temp1\graphics\telluric\day\
Athens\2011-07-03-17.png' @ error/png.c/ReadPNGImage/3641.
mogrify.exe: unable to open image `*jpg': Invalid argument @ error/blob.c/OpenBl
ob/2588.
我找到了下面的代码:
同时,我还发现了以下代码:
[Reflection.Assembly]::LoadWithPartialName('System.Drawing')
$img=[Drawing.Image]::FromFile("$(cd)\Max.jpg")
$img.Save("$(cd)\max.gif", 'Gif')
$img.Dispose()
我如何使其在目录树中运行,并将PNG和TIFF文件转换为JPG格式?
[IO.Path]::ChangeExtension( $_.FullName, '.jpg' )
而不是手动字符串格式化。 - Emperor XLII