0

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)"
jamacoe
  • 519
  • 4
  • 16

1 Answers1

1

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.

xenoid
  • 8,396
  • 3
  • 23
  • 49
  • yes, I see your point about IM, but I want to get on with script-fu. I'll not just be converting files but also applying automatic alterings. About webp/avif: I think there is a huge difference. The quality off the converted images is on my screen almost idendical at the chosen quality (I mimiked the default settings from the Gimp UI, which are 90% qualitiy for webp and 50% for avif). I mean 95 KB vs. 7.510 KB in a mobil responsive world? I plan to use tags everywhere in HTML, with avif, webP and jpeg, in that order. – jamacoe Jul 17 '22 at 13:46
  • 1
    IM is very powerful, it is not just about changing formats.It can do color/exposure changes, text annotations, framing, cropping, etc... Also, before commiting to Avif/WebP, check that the browsers support them, but also check that the server software on your site does the right thing, some try to push these as plain downloadable binary files instead of images. – xenoid Jul 17 '22 at 14:51
  • Browser support avif: https://caniuse.com/?search=avif (modern main browsers ex. Safari, IE) ; fall back 1 webP: https://caniuse.com/?search=webp (all modern ex. IE, even Safari latest) ; fall back 2 jpeg for any other. For Apache: .htaccess: 'AddType image/avif avif' and 'AddType image/avif-sequence avifs' – jamacoe Jul 18 '22 at 06:52