Skip to content

Commit

Permalink
Fixed input files not found when they're on a different drive than th…
Browse files Browse the repository at this point in the history
…e script

also added converters for JPG and PNG
  • Loading branch information
ThreeDeeJay committed May 30, 2022
1 parent 6441581 commit 0b64a4f
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cwebp.exe
*.exe
*.zip
76 changes: 76 additions & 0 deletions JPG-JXL.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
@echo off

SETlocal EnableExtensions
SETlocal EnableDelayedExpansion

TITLE JXL lossless batch converter - By 3DJ

SET InputFormat=JPG

pushd "%~dp0"
IF NOT "%~1"=="" (
IF EXIST "%~1/*" (
CD "%~1"
pushd "%~1"
SET "OutputPath=%~1\"
) ELSE (
For %%A in ("%~1") do (
CALL :Convert %%A "%%~dpA%%~nA.jxl"
PAUSE
EXIT
)
)
)

ECHO.
ECHO Press any key to convert all the !InputFormat! files in this folder and subfolders
ECHO Output format: JXL lossless
IF DEFINED OutputPath (
ECHO Output folder: !OutputPath!
) ELSE (
ECHO Output folder: JXL\
)
ECHO Folder structure: Same as input relative path
ECHO.
ECHO - To generate JXL files in the same folder as the input files,
ECHO close this window and drag the folder/file into the .bat file.
ECHO - Existing JXL files will be skipped,
ECHO so you can stop and resume batch conversion later if needed.
PAUSE >NUL
ECHO.

FOR /R %%A in (*.*) do (
IF /I "%%~xA"==".!InputFormat!" (
SET "OutputPath=%%~dpA"
IF "%~1"=="" (
SET "OutputPath=%~dp0JXL\!OutputPath:%~dp0=!"
IF NOT EXIST "!OutputPath!" (
MKDIR "!OutputPath!"
)
)
CALL :Convert "%%A" "!OutputPath!%%~nA.jxl"
)
)
ECHO Press any key to open the output folder
PAUSE
"!OutputPath!"

:Convert
IF NOT EXIST %2 (
CALL :Encode %1 %2
) ELSE (
For %%F in (%2) do (SET Filesize=%%~zF)
if !Filesize! EQU 0 (
ECHO %2 already exists, but seems corrupted/empty. Re-converting...
CALL :Encode %1 %2
) ELSE (
ECHO %2 already exists. Skipping...
)
)
EXIT /B

:Encode
ECHO Encoding %2
"%~dp0cjxl.exe" %1 %2 --verbose --quality=100 --effort=9
ECHO.
EXIT /B
7 changes: 5 additions & 2 deletions JPS-JXL.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ SETlocal EnableDelayedExpansion

TITLE JXL lossless batch converter - By 3DJ

SET InputFormat=JPS

pushd "%~dp0"
IF NOT "%~1"=="" (
IF EXIST "%~1/*" (
CD "%~1"
pushd "%~1"
SET "OutputPath=%~1\"
) ELSE (
For %%A in ("%~1") do (
Expand All @@ -20,7 +23,7 @@ IF NOT "%~1"=="" (
)

ECHO.
ECHO Press any key to convert all the JPS files in this folder and subfolders
ECHO Press any key to convert all the !InputFormat! files in this folder and subfolders
ECHO Output format: JXL lossless
IF DEFINED OutputPath (
ECHO Output folder: !OutputPath!
Expand All @@ -37,7 +40,7 @@ PAUSE >NUL
ECHO.

FOR /R %%A in (*.*) do (
IF /I "%%~xA"==".jps" (
IF /I "%%~xA"==".!InputFormat!" (
SET "OutputPath=%%~dpA"
IF "%~1"=="" (
SET "OutputPath=%~dp0JXL\!OutputPath:%~dp0=!"
Expand Down
76 changes: 76 additions & 0 deletions PNG-WebP.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
@echo off

SETlocal EnableExtensions
SETlocal EnableDelayedExpansion

TITLE WebP lossless batch converter - By 3DJ

SET InputFormat=PNG

pushd "%~dp0"
IF NOT "%~1"=="" (
IF EXIST "%~1/*" (
CD "%~1"
pushd "%~1"
SET "OutputPath=%~1\"
) ELSE (
For %%A in ("%~1") do (
CALL :Convert %%A "%%~dpA%%~nA.webp"
PAUSE
EXIT
)
)
)

ECHO.
ECHO Press any key to convert all the !InputFormat! files in this folder and subfolders
ECHO Output format: WebP lossless
IF DEFINED OutputPath (
ECHO Output folder: !OutputPath!
) ELSE (
ECHO Output folder: WebP\
)
ECHO Folder structure: Same as input relative path
ECHO.
ECHO - To generate WebP files in the same folder as the input files,
ECHO close this window and drag the folder/file into the .bat file.
ECHO - Existing WebP files will be skipped,
ECHO so you can stop and resume batch conversion later if needed.
PAUSE >NUL
ECHO.

FOR /R %%A in (*.*) do (
IF /I "%%~xA"==".!InputFormat!" (
SET "OutputPath=%%~dpA"
IF "%~1"=="" (
SET "OutputPath=%~dp0WebP\!OutputPath:%~dp0=!"
IF NOT EXIST "!OutputPath!" (
MKDIR "!OutputPath!"
)
)
CALL :Convert "%%A" "!OutputPath!%%~nA.webp"
)
)
ECHO Press any key to open the output folder
PAUSE
"!OutputPath!"

:Convert
IF NOT EXIST %2 (
CALL :Encode %1 %2
) ELSE (
For %%F in (%2) do (SET Filesize=%%~zF)
if !Filesize! EQU 0 (
ECHO %2 already exists, but seems corrupted/empty. Re-converting...
CALL :Encode %1 %2
) ELSE (
ECHO %2 already exists. Skipping...
)
)
EXIT /B

:Encode
ECHO Encoding %2
"%~dp0cwebp.exe" -v -mt -noasm -metadata all -progress -lossless -z 8 -m 6 -q 99 %1 -o %2
ECHO.
EXIT /B
7 changes: 5 additions & 2 deletions PNS-WebP.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ SETlocal EnableDelayedExpansion

TITLE WebP lossless batch converter - By 3DJ

SET InputFormat=PNS

pushd "%~dp0"
IF NOT "%~1"=="" (
IF EXIST "%~1/*" (
CD "%~1"
pushd "%~1"
SET "OutputPath=%~1\"
) ELSE (
For %%A in ("%~1") do (
Expand All @@ -20,7 +23,7 @@ IF NOT "%~1"=="" (
)

ECHO.
ECHO Press any key to convert all the PNS files in this folder and subfolders
ECHO Press any key to convert all the !InputFormat! files in this folder and subfolders
ECHO Output format: WebP lossless
IF DEFINED OutputPath (
ECHO Output folder: !OutputPath!
Expand All @@ -37,7 +40,7 @@ PAUSE >NUL
ECHO.

FOR /R %%A in (*.*) do (
IF /I "%%~xA"==".pns" (
IF /I "%%~xA"==".!InputFormat!" (
SET "OutputPath=%%~dpA"
IF "%~1"=="" (
SET "OutputPath=%~dp0WebP\!OutputPath:%~dp0=!"
Expand Down

0 comments on commit 0b64a4f

Please sign in to comment.