(10-07-2024, 11:01 PM)Ofnuts Wrote: file-webp-save2 takes 19 arguments and you are only showing 2.
They are all there, see below last code section, i did put the full code
The thing is if I use only
(while (> i 0)
(set! image (vector-ref (cadr (gimp-image-list)) (- i 1)))
(if (= KeepName 0)
(set! newFileName (string-append inDir
pathchar inFileName
(substring "0000000" (string-length
(number->string (+ inFileNumber i))))
(number->string (+ inFileNumber (- ii i))) ".webp"))
)
This part works as intended, (if (= KeepName 0) ➤ it's for if SF-TOGGLE "Keep the original name" FALSE
but if I add the below code, that part below throw an error when the SF-Toggle is checked > SF-TOGGLE "Keep the original name" TRUE
(if (= KeepName 1)
(set! newFileName (string-append inDir
pathchar (car (gimp-image-get-filename image)) ".webp"))
)
i would like to concatenate the path + original image name + extension (here webp), It is to propose if user wants to keep the original image name or not,
I also read there > https://developer.gimp.org/api/2.0/libgi...t-filename
that "gimp-image-get-filename" returns The filename. The returned value must be freed with g_free().
What does it mean "must be freed with g_free()"? what is g_free()?
The full script
Code:
(define (script-fu-pxl-save-all-images-as-webp inDir inAskAfter inKeepName inFileName inFileNumber inPreset inLossLess inQuality inAlphaQuality inAnimation inLoop inMiniSize inKeyframe inExif inIPTC inXMP inThumbnail inDelay inForceDelay runChoice)
(let* (
(i (car (gimp-image-list)))
(ii (car (gimp-image-list)))
(image)
(isInteractive)
(KeepName)
(newFileName "")
(pathchar (if (equal?
(substring gimp-dir 0 1) "/") "/" "\\"))
(webPreset)
(isLossless)
(qualityImage)
(qualityAlpha)
(isAnimation)
(isLoop)
(isMinimize)
(keyframeNum)
(isExif)
(isIPTC)
(isXMP)
(isThumb)
(delayNum)
(isForceDelay)
)
(set! KeepName
(cond
((equal? inKeepName FALSE) 0 )
((equal? inKeepName TRUE) 1 )
)
)
(set! isInteractive
(cond
(( equal? runChoice 0 ) RUN-NONINTERACTIVE )
(( equal? runChoice 1 ) RUN-INTERACTIVE )
(( equal? runChoice 2 ) RUN-WITH-LAST-VALS )
)
)
(set! webPreset ; re-order as I did "Picture" first
(cond
((equal? inPreset 0) 1 )
((equal? inPreset 1) 2 )
((equal? inPreset 2) 3 )
((equal? inPreset 3) 4 )
((equal? inPreset 4) 5 )
((equal? inPreset 5) 0 )
)
)
(set! isLossless
(cond
((equal? inLossLess FALSE) 0 )
((equal? inLossLess TRUE) 1 )
)
)
(set! qualityImage inQuality )
(set! qualityAlpha inAlphaQuality )
(set! isAnimation
(cond
((equal? inAnimation FALSE) 0 )
((equal? inAnimation TRUE) 1 )
)
)
(set! isLoop
(cond
((equal? inLoop FALSE) 0 )
((equal? inLoop TRUE) 1 )
)
)
(set! isMinimize
(cond
((equal? inMiniSize FALSE) 0 )
((equal? inMiniSize TRUE) 1 )
)
)
(set! keyframeNum inKeyframe)
(set! isExif
(cond
((equal? inExif FALSE) 0 )
((equal? inExif TRUE) 1 )
)
)
(set! isIPTC
(cond
((equal? inIPTC FALSE) 0 )
((equal? inIPTC TRUE) 1 )
)
)
(set! isXMP
(cond
((equal? inXMP FALSE) 0 )
((equal? inXMP TRUE) 1 )
)
)
(set! isThumb
(cond
((equal? inThumbnail FALSE) 0 )
((equal? inThumbnail TRUE) 1 )
)
)
(set! delayNum inDelay)
(set! isForceDelay
(cond
((equal? inForceDelay FALSE) 0 )
((equal? inForceDelay TRUE) 1 )
)
)
(while (> i 0)
(set! image (vector-ref (cadr (gimp-image-list)) (- i 1)))
(if (= KeepName 0)
(set! newFileName (string-append inDir
pathchar inFileName
(substring "0000000" (string-length
(number->string (+ inFileNumber i))))
(number->string (+ inFileNumber (- ii i))) ".webp"))
)
(if (= KeepName 1)
(set! newFileName (string-append inDir
pathchar (car (gimp-image-get-filename image)) ".webp"))
)
(file-webp-save2 isInteractive
image
(car (gimp-layer-new-from-visible image image "export"))
newFileName
newFileName
webPreset ; preset 0=default 1=pic 2=photo 3=drawing 4=icon 5=text
isLossless ; Use lossless encoding (0/1)
qualityImage ; Quality of the image (0 <= quality <= 100)
qualityAlpha ; alpha-quality 0<>100
isAnimation ; Use layers for animation (0/1)
isLoop ; Loop animation infinitely (0/1)
isMinimize ; Minimize animation size (0/1)
keyframeNum ; Maximum distance between key-frames (>=0)
isExif ; Toggle saving exif data (0/1)
isIPTC ; Toggle saving iptc data (0/1) works only if save XMP data is also checked ?
isXMP ; Toggle saving xmp data (0/1)
isThumb ; Toggle saving thumbnail (0/1)
delayNum ; Delay to use when timestamps are not available or forced
isForceDelay ; Force delay on all frames (0/1)
)
(if (not (= inAskAfter TRUE)) (gimp-image-clean-all image))
(set! i (- i 1))
)))
(script-fu-register "script-fu-pxl-save-all-images-as-webp" ; script-fu-register-filter for gimp 2.99
"1 - As WebP..."
"Export all opened images at once as WebP with your settings..."
"PixLab"
"GPL-v2+"
"2023/12/12"
"*"
SF-DIRNAME "Select a directory to export your images" "Desktop"
SF-TOGGLE "Ask me to save the XCF when closing GIMP or an image" TRUE
SF-TOGGLE "Keep the original name" TRUE
SF-STRING "Input an image base name" "IMAGE-"
SF-ADJUSTMENT "Input a start number for image name auto-numbering" (list 1 0 999999 1 100 0 SF-SPINNER)
SF-OPTION "Select a WebP Preset" (list "Picture" "Photo" "Drawing" "Icon" "Text" "Default")
SF-TOGGLE "Use lossless encoding" FALSE
SF-ADJUSTMENT "Quality of the image" (list 90 0 100 1 1 0 SF-SLIDER)
SF-ADJUSTMENT "Quality of Transparency" (list 90 0 100 1 1 0 SF-SLIDER)
SF-TOGGLE "Use Layers for Animation" FALSE
SF-TOGGLE "Loop Animation Infinitely" TRUE
SF-TOGGLE "Minimize Animation Size" FALSE
SF-ADJUSTMENT "Maximum distance between key-frames:\n 0 = No Keyframes:\n 1 = All Frames are Keyframes" (list 50 0 10000 1 1 0 SF-SPINNER)
SF-TOGGLE "Save Exif Data" TRUE
SF-TOGGLE "Save IPTC Data" FALSE
SF-TOGGLE "Save XMP Data" FALSE
SF-TOGGLE "Save Thumbnail" FALSE
SF-ADJUSTMENT "Delay to use between frames when unspecified" (list 100 0 10000 1 1 0 SF-SPINNER)
SF-TOGGLE "Use delay entered above for all frames" FALSE
SF-OPTION "Select How to Export (Explanations in the manual)" (list "Automated: Above settings for all images" "Full control: You confirm each setting on each image" "Use settings from latest Export")
)
(script-fu-menu-register "script-fu-pxl-save-all-images-as-webp" "<Image>/File/E_xport/Export All Images As")
Patrice