Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于ImageMagick转换windows上目录和子目录中所有文件的批处理命令_Windows_Batch File_Svg_Imagemagick_Imagemagick Convert - Fatal编程技术网

用于ImageMagick转换windows上目录和子目录中所有文件的批处理命令

用于ImageMagick转换windows上目录和子目录中所有文件的批处理命令,windows,batch-file,svg,imagemagick,imagemagick-convert,Windows,Batch File,Svg,Imagemagick,Imagemagick Convert,我在一个文件夹和子文件夹中有数千个SVG。我想要的是将它们批量转换为jpg或png图像 有人能帮我为ImageMagick(windows)编写一个命令吗?它可以找到所有svg并将其转换为jpg/png,使用它们的原始名称,并将它们保存在相同的目录中 以下是示例结构: C:\SVG\BusinessMan.svg C:\SVG\Models\Home.svg C:\SVG\Underlines\underline.svg 转换后我希望它是这样的: C:\SVG\BusinessMan.svg

我在一个文件夹和子文件夹中有数千个SVG。我想要的是将它们批量转换为jpgpng图像

有人能帮我为ImageMagick(windows)编写一个命令吗?它可以找到所有svg并将其转换为jpg/png,使用它们的原始名称,并将它们保存在相同的目录中

以下是示例结构:

C:\SVG\BusinessMan.svg
C:\SVG\Models\Home.svg
C:\SVG\Underlines\underline.svg
转换后我希望它是这样的:

C:\SVG\BusinessMan.svg
C:\SVG\BusinessMan.jpg
C:\SVG\Models\Home.svg
C:\SVG\Models\Home.jpg
C:\SVG\Underlines\underline.svg
C:\SVG\Underlines\underline.jpg

从根文件夹中尝试使用带有
/R
标志的
FOR
循环:

FOR /R %a IN (*.svg) DO convert "%~a" "%~dpna.jpg"
此命令将转换启动命令的根文件夹下子目录中的所有
.svg
文件

上述命令适用于命令行,如果您计划在批处理文件(.bat)中使用该命令,请记住使用
%%
而不是
%%

FOR /R %%a IN (*.svg) DO convert "%%~a" "%%~dpna.jpg"

有关更多信息,请参阅Imagemagick文档的第页

您不需要shell脚本,只需使用
mogrify
命令即可

cd到您的映像目录

mogrify -format png *.svg

当我在许多子目录中有许多图像要处理时,我从各种在线资源创建了以下脚本来转换文件。此脚本还包括一个进度显示。它已经用ImageMagick 7进行了测试。我希望你觉得它有用



或者说是最好的解决方案!使用
-format
选项可防止文件被覆盖。此处的文档:还有
-path
选项,用于将输出写入其他文件夹,而不是覆盖find-名称'*.webp'-exec mogrify-格式png{}\;
#ImageMagick Recursive Powershell Script with Progress display
#This script will execute a command recursively on all folders and subfolders
#This script will display the filename of every file processed
#set the source folder for the images
$srcfolder = "C:\temp"
#set the destination folder for the images
$destfolder = "C:\temp"
#set the ImageMagick command
$im_convert_exe = "magick"
#set the source image format (wildcard must be specified)
$src_filter = "*.png"
#set the destination (output) image format
$dest_ext = "bmp"
#set the ImageMagick command options
$options = "-colorspace rgb -density 300 -depth 8 -alpha off"
#set the log file path and name
$logfile = "C:\temp\convert.log"
$fp = New-Item -ItemType file $logfile -force
#The following lines allow the display of all files that are being processed
$count=0
foreach ($srcitem in $(Get-ChildItem $srcfolder -include $src_filter -recurse))
{
$srcname = $srcitem.fullname
$partial = $srcitem.FullName.Substring( $srcfolder.Length )
$destname = $destfolder + $partial
$destname= [System.IO.Path]::ChangeExtension( $destname , $dest_ext )
$destpath = [System.IO.Path]::GetDirectoryName( $destname )

if (-not (test-path $destpath))
{
    New-Item $destpath -type directory | Out-Null
}
#the following line defines the contents of the convert command line
$cmdline =  $im_convert_exe + " `"" + $srcname  + "`"" + $options + " `"" + $destname + "`" " 
#the following line runs the command
invoke-expression -command $cmdline  
$destitem = Get-item $destname
$info = [string]::Format( "{0} `t {1} `t {2} `t {3} `t {4} `t {5}", $count, $partial, $srcname, $destname, $srcitem.Length, $destitem.Length )
echo $info
Add-Content $fp $info
$count=$count+1
}