Getting Error( : 22091) >: argument 1 must be: number - GIMP Script-fu

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Getting Error( : 22091) >: argument 1 must be: number - GIMP Script-fu



I have many images about 100 with me, and i need to resize all the images using the scaling factor. But, when i run the script, it shows me the following error


Error: ( : 22091) >: argument 1 must be: number



I am not an expert in Script-Fu, so I could not find any resources that can help me. Below is my script, and any help would be appreciated.


(define (batch-resize pattern scaleFactor)
(let* ((filelist (cadr (file-glob pattern 1))))
(while (not (null? filelist))
(let* ((filename (car filelist))
(image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
(drawable (car (gimp-image-get-active-layer image)))
(imageWidth) (gimp-image-width image)
(imageHeight) (gimp-image-height image))
(let * ((imageFactor 1))
(if (> imageWidth imageHeight)
((set! imageFactor (/ imageWidth scaleFactor))) ((set! imageFactor (/ imageHeight scaleFactor))))
(set! imageWidth (/ imageWidth imageFactor))
(set! imageHeight (/ imageHeight imageFactor)))
(gimp-image-scale-full image imageWidth imageHeight INTERPOLATION-CUBIC)
(gimp-file-save RUN-NONINTERACTIVE image drawable filename filename)
(gimp-image-delete image))
(set! filelist (cdr filelist)))))





1) doing that with Gimp is complete overkill, see command-line utilities such as ImageMagick instead, and 2) any hint at the instruction/API call that causes it?
– xenoid
Feb 22 at 9:47





Also, add a few gimp-message calls in you code to show some variables. A potential culprit could be "image" if the image didn't load correctly
– xenoid
Feb 22 at 9:51





@xenoid re: 1) You have no idea what OP's motivations are and really shouldn't discount their approach without any context. They could be undertaking this exercise in order to learn Scheme, the Gimp plugin API or for an almost endless number of other reasons.
– pdoherty926
Aug 20 at 16:26





My experience (and I have been helping people with Gimp and Gimp scripting for over 8 years), is that these questions usually come from people who have only considered Gimp and don't know about the other tools (the one exception was someone whose employer mandated Gimp...).
– xenoid
Aug 20 at 20:52




1 Answer
1



You've got two issues, the first being you're not assigning imageWidth or imageHeight. Your brackets encapsulating the fetch image width/height calls go nowhere. So when the (> imageWidth imageHeight) is evaluated, imageWidth/imageHeight are not numbers.
(imageWidth) (gimp-image-width image) should be (imageWidth (gimp-image-width image)) to assign the return value.


imageWidth


imageHeight


(> imageWidth imageHeight)


(imageWidth) (gimp-image-width image)


(imageWidth (gimp-image-width image))



But the other problem is that, while the gimp documentation says it returns an INT32 (from what I could tell), most gimp api calls actually return a list, even if there is only one element in the list (See tutorial/docs). You need to call car on the result, which grabs the first element of the list, to use it in scheme.


car



Personal preference, but you might find it easier to see syntax/scoping issues with indenting.


(define (batch-resize pattern scaleFactor)
(let* ((filelist (cadr (file-glob pattern 1))))
(while (not (null? filelist))
(let* (
(filename (car filelist))
(image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
(drawable (car (gimp-image-get-active-layer image)))
(imageWidth (car (gimp-image-width image)))
(imageHeight (car (gimp-image-height image)))
)
(let * ((imageFactor 1))
(if (> imageWidth imageHeight)
((set! imageFactor (/ imageWidth scaleFactor)))
((set! imageFactor (/ imageHeight scaleFactor)))
)
(set! imageWidth (/ imageWidth imageFactor))
(set! imageHeight (/ imageHeight imageFactor))
)
(gimp-image-scale-full image imageWidth imageHeight INTERPOLATION-CUBIC)
(gimp-file-save RUN-NONINTERACTIVE image drawable filename filename)
(gimp-image-delete image)
)
(set! filelist (cdr filelist))
)
)
)






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard