Gimp 'gimp-image-convert-indexed' produces huge files

315 Views Asked by At

I am writing a script (my first script-fu) to export .jpeg to .avif and .webp, and I want to optimize the files for the web. Somewhere I read the suggestion to change from RGB to an indexed color palette, so I implemented the procedure gimp-image-convert-indexed. I was expecting smaller, web optimized files, but the opposite happened. The output resulted in huge files:

Original jpeg: 7.510 KB

Exported files without gimp-image-convert-indexed:
.avif: 95 KB
.webp: 2.052 KB

Exported files with gimp-image-convert-indexed:
.avif: 6.337 KB
.webp: 19.393 KB

Did I sent a parameter wrong? Or is the whole idea of using 'gimp-image-convert-indexed' nonsense?
(Aside: any other obvious flaws in my beginner's script? Comments and hints welcome.)

convert.scm:

    (define (filename-basename orig-name)
        (car (strbreakup orig-name "."))
    )
    
    (define 
        (convert in_filename WebP Avif)
    
        (let* (
                (image (car (gimp-file-load RUN-NONINTERACTIVE in_filename in_filename)))
                (drawable (car (gimp-image-flatten image)))
                (outWebP (string-append (filename-basename in_filename) ".webP"))
                (outAvif (string-append (filename-basename in_filename) ".avif"))
              )
    
            ; small output files sizes without this line, huge with:
            (gimp-image-convert-indexed image CONVERT-DITHER-FS CONVERT-PALETTE-WEB 0 0 1 "")
    
            (cond ((equal? WebP 1)
                (gimp-message "exporting as .webP")
                (file-webp-save2 RUN-NONINTERACTIVE image drawable outWebP outWebP 0 0 90 100 0 0 0 0 0 0 0 0 0 0)))
    
            (cond ((equal? Avif 1)
                (gimp-message "exporting as .avif")
                (file-heif-av1-save RUN-NONINTERACTIVE image drawable outAvif outAvif 50 0)))
    
            (gimp-image-delete image)       
        )
    )

Invoke under windows:

    gimp-console-2.10 -idf -b "(convert \"IMG.jpg\" 1 1)" -b "(gimp-quit 0)"
1

There are 1 best solutions below

3
xenoid On

Converting to indexed is nonsense since your output format does not support it. Color-indexing may reduce image size on PNG (which is the only format I know with both color-indexed and full-RGB formats).

I don't see much benefit on WebP/Avif over Jpeg, for the same final visual quality. In other words,there are JPEG options that work just as well: reducing quality or increasing chroma sub-sampling.

Also to batch-convert images, ImageMagick is much easier to code around than Gimp.