svgtype-conversionresizegimpimage-scaling

Resize and convert a SVG image using a gimp script


I'm using gimp 2.10 on a Debian 12 system.

I need to use gimp because, after some manuals tests using gimp graphical interface, I noticed the quality of resized/converted images is better than with imagemagik or inkscape.

My gimp script successfully convert the SVG to PNG, but it doesn't resize it.

Here is my script:

(define (convertresize in_filename out_filename width height)
    (let* (
            (image (car (gimp-file-load RUN-NONINTERACTIVE in_filename "")))
            (drawable (car (gimp-image-get-active-layer image)))
            (gimp-image-scale-full image width height INTERPOLATION-CUBIC)
            (gimp-layer-resize-to-image-size drawable)
        )
        (gimp-file-save RUN-NONINTERACTIVE image drawable out_filename out_filename)
        (gimp-image-delete image)
    )
)

The script is in ~/.config/GIMP/2.10/scripts folder. I launch it with the following command:

gimp -i -b '(convertresize "./image.svg" "./image.png" 24 24)' -b '(gimp-quit 0)'

So, I would like to know why my script doesn't resize the image.


Solution

  • The transformations done to the image have to be done outside the section that loads the image.

    Here is the correct code:

    (define (convertresize in_filename out_filename width height)
        (let* (
                (image (car (gimp-file-load RUN-NONINTERACTIVE in_filename "")))
                (drawable (car (gimp-image-get-active-layer image)))
            )
            (gimp-image-undo-disable image)
            (gimp-image-scale-full image width height INTERPOLATION-CUBIC)
            (gimp-layer-resize-to-image-size drawable)
            (gimp-file-save RUN-NONINTERACTIVE image drawable out_filename out_filename)
            (gimp-image-delete image)
        )
    )