jimminning / ConvertTo-Png

A PowerShell script that converts image files to PNG format
MIT License
6 stars 3 forks source link

ConvertTo-Png

A PowerShell script that converts image files to PNG format

This is a direct conversion from David Anson's ConvertTo-Jpeg

Overview

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.)

Related

Examples

Converting Files

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

Formats

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

HEIC/HEIF

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.

WEBP

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.