Skip to content

Instantly share code, notes, and snippets.

@Alexander01998
Last active July 23, 2024 12:21
Show Gist options
  • Save Alexander01998/0a0f8e1634736b341c4e74ec0ccbeb46 to your computer and use it in GitHub Desktop.
Save Alexander01998/0a0f8e1634736b341c4e74ec0ccbeb46 to your computer and use it in GitHub Desktop.
A registry mod to convert images between JPG and PNG formats. Only tested on Windows 10. USE AT YOUR OWN RISK!

convert to jpg screenshot convert to png screenshot

To install this registry mod, simply download the image_converters.reg file and double-click to run it. You will need admin permissions.

WARNING: Editing the Windows Registry can cause serious problems if not done correctly. Always back up your data and remember that this is just some random script on GitHub with absolutely no warranty.

(For those new to GitHub, you can download files by clicking the "Raw" button and then pressing CTRL+S to save.)

Windows Registry Editor Version 5.00
; Remove existing Convert to JPG entries (if any)
[-HKEY_CLASSES_ROOT\SystemFileAssociations\.png\shell\ConvertToJPG]
; Add "Convert to JPG" menu for PNG files
[HKEY_CLASSES_ROOT\SystemFileAssociations\.png\shell\ConvertToJPG]
"MUIVerb"="Convert to JPG"
"subcommands"=""
; Register subcommands
[HKEY_CLASSES_ROOT\SystemFileAssociations\.png\shell\ConvertToJPG\shell\01_Convert_JPG100]
@="100% Quality"
[HKEY_CLASSES_ROOT\SystemFileAssociations\.png\shell\ConvertToJPG\shell\01_Convert_JPG100\command]
@="powershell.exe -ExecutionPolicy Bypass -Command \"$output = [System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName('%1'), [System.IO.Path]::GetFileNameWithoutExtension('%1') + '_100.jpg'); Add-Type -AssemblyName System.Drawing; $image = [System.Drawing.Image]::FromFile('%1'); $jpegCodec = [System.Drawing.Imaging.ImageCodecInfo]::GetImageEncoders() | Where-Object {$_.FormatID -eq [System.Drawing.Imaging.ImageFormat]::Jpeg.Guid}; $encoderParams = New-Object System.Drawing.Imaging.EncoderParameters(1); $encoderParams.Param[0] = New-Object System.Drawing.Imaging.EncoderParameter([System.Drawing.Imaging.Encoder]::Quality, 100L); $image.Save($output, $jpegCodec, $encoderParams); $image.Dispose()\""
[HKEY_CLASSES_ROOT\SystemFileAssociations\.png\shell\ConvertToJPG\shell\02_Convert_JPG95]
@="95% Quality"
[HKEY_CLASSES_ROOT\SystemFileAssociations\.png\shell\ConvertToJPG\shell\02_Convert_JPG95\command]
@="powershell.exe -ExecutionPolicy Bypass -Command \"$output = [System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName('%1'), [System.IO.Path]::GetFileNameWithoutExtension('%1') + '_95.jpg'); Add-Type -AssemblyName System.Drawing; $image = [System.Drawing.Image]::FromFile('%1'); $jpegCodec = [System.Drawing.Imaging.ImageCodecInfo]::GetImageEncoders() | Where-Object {$_.FormatID -eq [System.Drawing.Imaging.ImageFormat]::Jpeg.Guid}; $encoderParams = New-Object System.Drawing.Imaging.EncoderParameters(1); $encoderParams.Param[0] = New-Object System.Drawing.Imaging.EncoderParameter([System.Drawing.Imaging.Encoder]::Quality, 95L); $image.Save($output, $jpegCodec, $encoderParams); $image.Dispose()\""
[HKEY_CLASSES_ROOT\SystemFileAssociations\.png\shell\ConvertToJPG\shell\03_Convert_JPG90]
@="90% Quality"
[HKEY_CLASSES_ROOT\SystemFileAssociations\.png\shell\ConvertToJPG\shell\03_Convert_JPG90\command]
@="powershell.exe -ExecutionPolicy Bypass -Command \"$output = [System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName('%1'), [System.IO.Path]::GetFileNameWithoutExtension('%1') + '_90.jpg'); Add-Type -AssemblyName System.Drawing; $image = [System.Drawing.Image]::FromFile('%1'); $jpegCodec = [System.Drawing.Imaging.ImageCodecInfo]::GetImageEncoders() | Where-Object {$_.FormatID -eq [System.Drawing.Imaging.ImageFormat]::Jpeg.Guid}; $encoderParams = New-Object System.Drawing.Imaging.EncoderParameters(1); $encoderParams.Param[0] = New-Object System.Drawing.Imaging.EncoderParameter([System.Drawing.Imaging.Encoder]::Quality, 90L); $image.Save($output, $jpegCodec, $encoderParams); $image.Dispose()\""
[HKEY_CLASSES_ROOT\SystemFileAssociations\.png\shell\ConvertToJPG\shell\04_Convert_JPG85]
@="85% Quality"
[HKEY_CLASSES_ROOT\SystemFileAssociations\.png\shell\ConvertToJPG\shell\04_Convert_JPG85\command]
@="powershell.exe -ExecutionPolicy Bypass -Command \"$output = [System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName('%1'), [System.IO.Path]::GetFileNameWithoutExtension('%1') + '_85.jpg'); Add-Type -AssemblyName System.Drawing; $image = [System.Drawing.Image]::FromFile('%1'); $jpegCodec = [System.Drawing.Imaging.ImageCodecInfo]::GetImageEncoders() | Where-Object {$_.FormatID -eq [System.Drawing.Imaging.ImageFormat]::Jpeg.Guid}; $encoderParams = New-Object System.Drawing.Imaging.EncoderParameters(1); $encoderParams.Param[0] = New-Object System.Drawing.Imaging.EncoderParameter([System.Drawing.Imaging.Encoder]::Quality, 85L); $image.Save($output, $jpegCodec, $encoderParams); $image.Dispose()\""
[HKEY_CLASSES_ROOT\SystemFileAssociations\.png\shell\ConvertToJPG\shell\05_Convert_JPG80]
@="80% Quality"
[HKEY_CLASSES_ROOT\SystemFileAssociations\.png\shell\ConvertToJPG\shell\05_Convert_JPG80\command]
@="powershell.exe -ExecutionPolicy Bypass -Command \"$output = [System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName('%1'), [System.IO.Path]::GetFileNameWithoutExtension('%1') + '_80.jpg'); Add-Type -AssemblyName System.Drawing; $image = [System.Drawing.Image]::FromFile('%1'); $jpegCodec = [System.Drawing.Imaging.ImageCodecInfo]::GetImageEncoders() | Where-Object {$_.FormatID -eq [System.Drawing.Imaging.ImageFormat]::Jpeg.Guid}; $encoderParams = New-Object System.Drawing.Imaging.EncoderParameters(1); $encoderParams.Param[0] = New-Object System.Drawing.Imaging.EncoderParameter([System.Drawing.Imaging.Encoder]::Quality, 80L); $image.Save($output, $jpegCodec, $encoderParams); $image.Dispose()\""
[HKEY_CLASSES_ROOT\SystemFileAssociations\.png\shell\ConvertToJPG\shell\06_Convert_JPG75]
@="75% Quality"
[HKEY_CLASSES_ROOT\SystemFileAssociations\.png\shell\ConvertToJPG\shell\06_Convert_JPG75\command]
@="powershell.exe -ExecutionPolicy Bypass -Command \"$output = [System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName('%1'), [System.IO.Path]::GetFileNameWithoutExtension('%1') + '_75.jpg'); Add-Type -AssemblyName System.Drawing; $image = [System.Drawing.Image]::FromFile('%1'); $jpegCodec = [System.Drawing.Imaging.ImageCodecInfo]::GetImageEncoders() | Where-Object {$_.FormatID -eq [System.Drawing.Imaging.ImageFormat]::Jpeg.Guid}; $encoderParams = New-Object System.Drawing.Imaging.EncoderParameters(1); $encoderParams.Param[0] = New-Object System.Drawing.Imaging.EncoderParameter([System.Drawing.Imaging.Encoder]::Quality, 75L); $image.Save($output, $jpegCodec, $encoderParams); $image.Dispose()\""
; Remove existing Convert to PNG entries (if any)
[-HKEY_CLASSES_ROOT\SystemFileAssociations\.jpg\shell\ConvertToPNG]
; Add "Convert to PNG" menu for JPG files
[HKEY_CLASSES_ROOT\SystemFileAssociations\.jpg\shell\ConvertToPNG]
"MUIVerb"="Convert to PNG"
[HKEY_CLASSES_ROOT\SystemFileAssociations\.jpg\shell\ConvertToPNG\command]
@="powershell.exe -ExecutionPolicy Bypass -Command \"$output = [System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName('%1'), [System.IO.Path]::GetFileNameWithoutExtension('%1') + '.png'); Add-Type -AssemblyName System.Drawing; $image = [System.Drawing.Image]::FromFile('%1'); $image.Save($output, [System.Drawing.Imaging.ImageFormat]::Png); $image.Dispose()\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment