Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.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
Powershell 检查新文件并转换为dds_Powershell_Imagemagick - Fatal编程技术网

Powershell 检查新文件并转换为dds

Powershell 检查新文件并转换为dds,powershell,imagemagick,Powershell,Imagemagick,我有一个创建JPG的文件夹。当创建一个新的JPG时,我需要调整它的大小(例如到2048x2048像素),并将其转换为.dds(dxt1)。所有这些都是自动完成的 我开始使用Google批处理文件命令,然后了解到使用powershell可能会更好,并了解了ImageMagick converter。但我不确定这些,也不知道从哪里开始…我不是Windows批处理方面的专家,但您可以按照这些思路做一些事情。将以下代码另存为JPG2DDS.BAT,并使用 JPG2DDS 或者双击它 @ECHO OFF

我有一个创建JPG的文件夹。当创建一个新的JPG时,我需要调整它的大小(例如到2048x2048像素),并将其转换为.dds(dxt1)。所有这些都是自动完成的


我开始使用Google批处理文件命令,然后了解到使用powershell可能会更好,并了解了ImageMagick converter。但我不确定这些,也不知道从哪里开始…

我不是Windows批处理方面的专家,但您可以按照这些思路做一些事情。将以下代码另存为
JPG2DDS.BAT
,并使用

JPG2DDS
或者双击它

@ECHO OFF
REM Start of infinite loop monitoring directory for JPGs
:TOP
   echo Checking for files...
   REM Work through all JPEG files converting to DDS
   FOR /F %%f IN ( 'DIR /B *.JPG' ) DO (
      ECHO Processing file %%f...
      convert "%%f" -resize 2048x2048 "%%f.dds"
      REM If it worked, rename the original file so we don't do it again
      REM If it didn't work, we'll try again next time round
      IF %ERRORLEVEL% == 0 (
         ECHO Conversion successful
         REN "%%f" "%%f.converted"
      )
   )   
   REM Sleep so as not to overload Windows
   ECHO Sleeping...
   SLEEP 10
GOTO TOP
以上所有命令都以示例进行了描述

convert
命令是需要安装的ImageMagick的一部分。运行此脚本之前,请确保可以使用以下命令将单个JPEG转换为DDS:

convert someImage.jpg -resize 2048x2048 result.dds

谢谢你的回答。我试着弄脏我的手,但我还是没弄脏多少,所以我想我要找个朋友教我一点。