A PowerShell script that converts image files to PNG format
This is a direct conversion from David Anson's ConvertTo-Jpeg
ConvertTo-Png.ps1
is a PowerShell script that uses the Windows.Graphics.Imaging API to create a PNG-encoded copy of each image that is passed to it.
(The original file is not modified.)
- ConvertTo-Jpeg.ps1: A PowerShell script that converts RAW (and other) image files to the widely-supported JPEG format
- ConvertTo-Heic.ps1: A PowerShell script that converts image files to the efficient HEIC format
Passing parameters:
PS C:\T> .\ConvertTo-Png.ps1 C:\T\Pictures\IMG_1234.HEIC C:\T\Pictures\IMG_5678.HEIC C:\T\Pictures\IMG_90.PNG
C:\T\Pictures\IMG_1234.HEIC -> IMG_1234.HEIC.png
C:\T\Pictures\IMG_5678.HEIC -> IMG_5678.HEIC.png
C:\T\Pictures\IMG_90.PNG [Already PNG]
Pipeline via dir
:
PS C:\T> dir C:\T\Pictures | .\ConvertTo-Png.ps1
C:\T\Pictures\IMG_1234.HEIC -> IMG_1234.HEIC.png
C:\T\Pictures\IMG_5678.HEIC -> IMG_5678.HEIC.png
C:\T\Pictures\Kitten.png [Already PNG]
C:\T\Pictures\Notes.txt [Unsupported]
Pipeline via Get-ChildItem
:
PS C:\T> Get-ChildItem C:\T\Pictures -Filter *.HEIC | .\ConvertTo-Png.ps1
C:\T\Pictures\IMG_1234.HEIC -> IMG_1234.HEIC.png
C:\T\Pictures\IMG_5678.HEIC -> IMG_5678.HEIC.png
Decoder | Extensions |
---|---|
BMP Decoder | .BMP .DIB .RLE |
CUR Decoder | .CUR |
DDS Decoder | .DDS |
DNG Decoder | .DNG |
GIF Decoder | .GIF |
ICO Decoder | .ICO .ICON |
JPEG Decoder | .EXIF .JFIF .JPE .JPEG .JPG |
Microsoft Camera Raw Decoder | .ARW .CR2 .CRW .DNG .ERF .KDC .MRW .NEF .NRW .ORF .PEF .RAF .RAW .RW2 .RWL .SR2 .SRW |
Microsoft HEIF Decoder | .AVCI .AVCS .HEIC .HEICS .HEIF .HEIFS |
Microsoft Webp Decoder | .WEBP |
PNG Decoder | .PNG |
TIFF Decoder | .TIF .TIFF |
WMPhoto Decoder | .JXR .WDP |
Windows 10's April 2018 Update (version 1803) added support for HEIC/HEIF images to the Windows.Graphics.Imaging API.
ConvertTo-Jpeg.ps1
uses the new decoder automatically if it's available.
To enable the decoder, install the Microsoft HEIF and HEVC Media Extensions bundle (or else both of HEVC Video Extensions and HEIF Image Extensions).
Once done, the built-in Photos app (and other programs that use the Windows.Graphics.Imaging API) will be able to open HEIC/HEIF images.
If the default support for WebP images is missing or incomplete, consider installing the Microsoft Webp Image Extensions. As above, the built-in Photos app is a great way to verify support for WEBP images.