Variable scaling images for GIMP via batch file (Windows) error

I try to use batch to transform images into defined quality .jpg with tags and with file name normalization, plus generation of .png thumbnails restricted to max dimensions of 169×127 px, scaled proportionally. The thumbnails part of code doesn’t work.

Algorithm for part of code I need is simple:
Checks if original-width > original-height,
if true: new-height = 127, new-width = original-width * new-height / original-height
else: new-width = 169, new-height = original-height * new-width / original-width
Then just create .png with compression level = 7, name it as NEWFILE & “_t.png”

So it’s composed as below with support of ChatGPT – the .bat file accessing GIMP’s console:

%GIMP_PATH% -i -b "(let* ((image (car (gimp-file-load RUN-NONINTERACTIVE "%%F" "%%F"))) (drawable (car (gimp-image-get-active-layer image))) (original-width (car (gimp-image-width image))) (original-height (car (gimp-image-height image))) (new-width 169) (new-height 127) (if (> original-width original-height) ((gimp-image-scale image (round ((* (original-width) (/ (new-height) (original-height)))))) (new-height)) ((gimp-image-scale image (new-width) (round ((* (original-height) (/ (new-width) (original-width)))))))) (file-png-save RUN-NONINTERACTIVE image drawable (string-append "!NEWFILE!_t.png") (string-append "!NEWFILE!_t.png") 0 7 0 0 0 0 0) (gimp-image-delete image)))" -b "(gimp-quit 0)"

When launching .bat above part of code cause an error and does not save .png thumbnail. Full error message:

C:Program FilesGIMP 2bingimp-console-2.10.exe: GEGL-OSTRZEŻENIE: (../gegl/buffer/gegl-tile-handler-cache.c:1076):gegl_tile_cache_destroy: runtime check failed: (g_queue_is_empty (&cache_queue))
EEEEeEeek! 2 GeglBuffers leaked
To debug GeglBuffer leaks, set the environment variable GEGL_DEBUG to "buffer-alloc"

Full actual code of .bat, which works without above part:

@echo off
setlocal enabledelayedexpansion
chcp 65001

:: Prefix
set pref="arma3_"
set GIMP_PATH="C:Program FilesGIMP 2bingimp-console-2.10.exe"
if not exist %GIMP_PATH% (
    echo GIMP is not installed at %GIMP_PATH%. Please check the installation path.
    exit /b
)

for %%F in (*.jpg *.jpeg *.png *.bmp *.gif *.tiff) do (
    set FILE=%%~nF
    set EXT=%%~xF

    for /f "delims= eol=" %%A in ('powershell -NoLogo -NoProfile -Command "'!FILE!'.ToLower()"') do (set "STRING=%%~A")

    for /f "tokens=*" %%i in ('powershell -NoLogo -NoProfile -Command "($env:STRING) -replace '[()]','' -replace ' ','_' -replace 'ą','a' -replace 'ć','c' -replace 'ę','e' -replace 'ł','l' -replace 'ń','n' -replace 'ó','o' -replace 'ś','s' -replace 'ź','z' -replace 'ż','z'"') do (set STRING=%%i)

    set "NEWFILE=!pref!!STRING!"

    :: Convert to JPG with 97% quality
    %GIMP_PATH% -i -b "(let* ((image (car (gimp-file-load RUN-NONINTERACTIVE "%%F" "%%F"))) (drawable (car (gimp-image-get-active-layer image)))) (file-jpeg-save RUN-NONINTERACTIVE image drawable (string-append "!NEWFILE!.jpg") (string-append "!NEWFILE!.jpg") 0.97 0 0 0 "" 0 1 0 1) (gimp-image-delete image))" -b "(gimp-quit 0)"

    :: Convert to PNG with compression level 7 and scaled dimensions
    %GIMP_PATH% -i -b "(let* ((image (car (gimp-file-load RUN-NONINTERACTIVE "%%F" "%%F"))) (drawable (car (gimp-image-get-active-layer image))) (original-width (car (gimp-image-width image))) (original-height (car (gimp-image-height image))) (new-width 169) (new-height 127) (if (> original-width original-height) ((gimp-image-scale image (round ((* (original-width) (/ (new-height) (original-height)))))) (new-height)) ((gimp-image-scale image (new-width) (round ((* (original-height) (/ (new-width) (original-width)))))))) (file-png-save RUN-NONINTERACTIVE image drawable (string-append "!NEWFILE!_t.png") (string-append "!NEWFILE!_t.png") 0 7 0 0 0 0 0) (gimp-image-delete image)))" -b "(gimp-quit 0)"

)

echo All images have been processed.
pause

Sorry in advance that vital not working part is in a single line and has additional brackets, which was a way to try debug it. I’m just starting with .bat files and especially first thing related with GIMP (Script-Fu).

I tried to debug it, checking if phrasing is correct, used ChatGPT to check for errors and added additional brackets, nothing helped, error still appears.

New contributor

Frozen Mind is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật