如何将多个文件夹中的图像批量转换为 PNG8?

如何将多个文件夹中的图像批量转换为 PNG8?

我有 20 多个文件夹中的 4500 多张 PNG 24 图像,我想通过将它们转换为 PNG 8 来减小它们的大小。(补充:我尝试过压缩和其他 png 优化,但节省的容量不够,在 PS 中对 2 个文件夹的测试表明 PNG 8 应该不会对图像造成明显的质量下降)

当我尝试 PS CS3 Batch 时,它不会覆盖原始文件,并且它创建的新文件没有文件夹结构。有没有办法解决这个问题或者有其他工具可以解决这个问题?

我正在运行 OSX 但可以访问 Windows XP/7。

答案1

视图处理批处理/转换。Ctrl+ U:“工具->批处理...”

  • 覆盖、使用原始路径(作为输出)和/或保留子文件夹结构的选项。
  • 从转换选项卡中添加“转换 > 转换为颜色”转换。其中一个参数是位/像素。

答案2

这很麻烦,不是吗?这里有个窍门。录制您的操作并将其设为 png8 后,单击操作面板的右上角并选择插入菜单项。然后单击文件 --> 保存。单击确定。它现在应该是您操作中的最后一个子项。

现在,当您运行批处理时,内容将像预期的那样保留在其子文件夹中。

答案3

安装 ImageMagick 并使用 Powershell 运行

 
#--------------------------------------------------------------------

# Powershell script to recursively convert image formats
# Configuration
$srcfolder = "C:\test\Animals"
$destfolder = "C:\test\Animals"
#This ps1 file will add copy files to designated folder
#Do NOT use Mogrify or the original images will be deleted
$im_convert_exe = "convert.exe -density 300"
# with VECTOR files the density setting should come BEFORE the vector file
# or the image will be blurry.
# change src_filter to the format of the source files
$src_filter = "*.eps"
# change dest_ext to the format of the destination files
$dest_ext = "png"
$options = "-depth 8 -alpha off"
$logfile = "C:\temp\convert.log"
$fp = New-Item -ItemType file $logfile -force
$count=0
foreach ($srcitem in $(Get-ChildItem $srcfolder -include $src_filter -recurse))
{
    $srcname = $srcitem.fullname

    # Construct the filename and filepath for the output
    $partial = $srcitem.FullName.Substring( $srcfolder.Length )
    $destname = $destfolder + $partial
    $destname= [System.IO.Path]::ChangeExtension( $destname , $dest_ext )
    $destpath = [System.IO.Path]::GetDirectoryName( $destname )

    # Create the destination path if it does not exist
    if (-not (test-path $destpath))
    {
        New-Item $destpath -type directory | Out-Null
    }

    # Perform the conversion by calling an external tool
    $cmdline =  $im_convert_exe + " `"" + $srcname  + "`"" + $options + " `"" + $destname + "`" " 
    #echo $cmdline
    invoke-expression -command $cmdline

    # Get information about the output file    
    $destitem = Get-item $destname

    # Show and record information comparing the input and output files
    $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
} 

#--------------------------------------------------------------

 

相关内容