Chikan72
Newbie
- Dec 28, 2020
- 40
- 178
- 60
I did the same to put some of the comics on my Android Tablet... If you are using Windows and install ImageMagick, you can use my script:well, i will try to change formats and reduce the size of the biggest files, but just for those who are not posted yet or incomplete
Bash:
@echo off
setlocal
rem Check if ImageMagick is installed and in the PATH
where magick >nul 2>&1
if %errorlevel% neq 0 (
echo ImageMagick is not installed or not in the PATH. Please install it and add it to your PATH.
pause
exit /b 1
)
rem Define the initial quality setting (you may need to adjust this)
set "quality=70"
rem Use forfiles to loop through all .jpg files in the current folder and subfolders
for /d /r %%d in (.) do (
echo Processing: "%%~nd"
forfiles /p "%%~fd" /m *.jpg /c "cmd /c @echo @file" | findstr /r /c:"\.jpg$" | for /f "delims=" %%i in ('findstr /r /c:"\.jpg$"') do (
echo Processing "%%i"...
rem Get creation and modification dates using PowerShell
for /f "delims=" %%a in ('powershell -command "(Get-Item '%%i').CreationTime.ToString('yyyyMMddHHmmss.fff')"') do (
set "creationdate=%%a"
)
for /f "delims=" %%b in ('powershell -command "(Get-Item '%%i').LastWriteTime.ToString('yyyyMMddHHmmss.fff')"') do (
set "modifieddate=%%b"
)
rem Use ImageMagick to resample the image, keeping metadata and setting quality (no DPI change)
magick "%%i" -quality %quality% "%%i.tmp.jpg"
if errorlevel 1 (
echo Error processing "%%i". Skipping.
) else (
rem Replace the original file with the resampled file
del "%%i"
ren "%%i.tmp.jpg" "%%~nxi"
rem Restore the original creation and modification times using PowerShell
powershell -command "(Get-Item '%%i').CreationTime = [datetime]::ParseExact('%creationdate%', 'yyyyMMddHHmmss.fff', $null)"
powershell -command "(Get-Item '%%i').LastWriteTime = [datetime]::ParseExact('%modifieddate%', 'yyyyMMddHHmmss.fff', $null)"
rem Remove temporary variables
set "creationdate="
set "modifieddate="
)
)
)
echo Done.
pause
endlocal