Convert all images to jpg

后端 未结 2 1682
深忆病人
深忆病人 2021-01-01 00:09

I need to convert all images in folder and subfolders to jpg. I need to batch this process with command file. GUI tools needles for me I need the script.

I tried to

2条回答
  •  星月不相逢
    2021-01-01 00:55

    I've done something similar with converting a bitmap files to icon files here:

    http://sev17.com/2011/07/creating-icons-files/

    I adapted it to your requirements and test a function for converting image files to jpg:

    function ConvertTo-Jpg
    {
        [cmdletbinding()]
        param([Parameter(Mandatory=$true, ValueFromPipeline = $true)] $Path)
    
        process{
            if ($Path -is [string])
            { $Path = get-childitem $Path }
    
            $Path | foreach {
                $image = [System.Drawing.Image]::FromFile($($_.FullName));
                $FilePath = [IO.Path]::ChangeExtension($_.FullName, '.jpg');
                $image.Save($FilePath, [System.Drawing.Imaging.ImageFormat]::Jpeg);
                $image.Dispose();
            }
        }
    
     }
    
     #Use function:
     #Cd to directory w/ png files
     cd .\bin\pngTest
    
     #Run ConvertTo-Jpg function
     Get-ChildItem *.png | ConvertTo-Jpg
    

提交回复
热议问题