Skip to content

Instantly share code, notes, and snippets.

@altbdoor
Last active May 22, 2017 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save altbdoor/c9c56680f7d7307d54779b18b039396a to your computer and use it in GitHub Desktop.
Save altbdoor/c9c56680f7d7307d54779b18b039396a to your computer and use it in GitHub Desktop.
Converts PNG to JPG with png2jpeg.exe
#NoEnv
#NoTrayIcon
#SingleInstance force
SetWorkingDir %A_ScriptDir%
FileInstall, png2jpeg.exe, %A_Temp%\png2jpeg.exe, 0
; to compile this script, you will need to get png2jpeg.exe first
; https://sourceforge.net/projects/png2jpeg/
; https://autohotkey.com/board/topic/63952-dragdrop-file-onto-ahk-script-pathname-of-file-into-var/?p=403191
Loop %0%
{
PngPath := ""
GivenPath := %A_Index%
Loop %GivenPath%, 1
PngPath = %A_LoopFileLongPath%
; get the ext from path
PngPathExt = Substr(PngPath, -3)
StringLower, PngPathExt, PngPathExt
; simple check if its a png
If (PngPath != "" && PngPathExt == ".png") {
; prepare the jpg path
JpgPath := RegExReplace(PngPath, "i)\.png$", ".jpg")
; do your thang
RunWait, "%A_Temp%\png2jpeg.exe" -q 95 -o "%JpgPath%" "%PngPath%", , Hide
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment