Thu May 11, 2023 9:12 am
Thu May 11, 2023 4:28 pm
Thu May 11, 2023 4:33 pm
(gimp-brushes-get-list "Chalk.*")
(gimp-brush-get-info "Chalk 02 copy")
(gimp-brushes-get-list "")
C:\Users\YourUserName\AppData\Roaming\GIMP\2.10\brushes
; Retrieve the list of subfolders in strPath
(define (list-folder strPath)
(let* ( (lenPath (if (string? strPath) (+ (string-length strPath) 1) ; length after the last DIR-SEPARATOR
(error "7000 list-folder requires strPath as a string")
) )
(lstGlob (file-glob (string-append strPath DIR-SEPARATOR "*") 0))
(lstFull (if (and (list? lstGlob) (= (length lstGlob) 2)) ; file-glob returns (nbrDir lstFull)
(cadr lstGlob) ; Extract lstFull in 2nd position of lstGlob
(error "7010 list-folder cannot retrieve subfolders of " strPath)
) ) )
(let loop ( (lstFolder lstFull) ; List of full paths of subdirectories
(lstDir '()) ; List of subdirectories without the full path
)
(if (not(pair? lstFolder)) (reverse lstDir) ; Restore the alphabetic order
(loop (cdr lstFolder) (cons (substring (car lstFolder) lenPath) lstDir)) ; Cut the full path
) ) ) )
(list-folder (string-append gimp-data-directory DIR-SEPARATOR "brushes"))
Thu May 11, 2023 4:37 pm
; (Export-gbr-to-png "C:\\Tool\\Gimp\\forum\\GimpChat\\Brush\\Chalk-02-copy.gbr")
(define (Export-gbr-to-png fileGbr)
(let* ( (imgGbr (car (file-gbr-load RUN-NONINTERACTIVE fileGbr fileGbr)))
(layer (car (gimp-image-get-active-drawable imgGbr)))
(vPath (PathSplit fileGbr)) ; See KodiSave.scm
(pathPic (vector-ref vPath 1)) ; 0-based element in the vector
(filename (vector-ref vPath 2))
(lstFile (strbreakup filename ".")) ; split the filename into the basename and the fileExt
(basename (car lstFile))
(filePng (string-append pathPic DIR-SEPARATOR basename ".png"))
)
(gimp-display-new imgGbr)
(file-png-save RUN-NONINTERACTIVE imgGbr layer filePng filePng 0 9 0 0 0 0 0)
(gimp-image-clean-all imgGbr)
(displayln (string-append "Export-gbr-to-png SUCCESSFULLY exported \"" basename "\".gbr to " filePng))
) )
(Export-gbr-to-png "C:\\Tool\\Gimp\\forum\\GimpChat\\Brush\\Chalk-02-copy.gbr")
Fri May 12, 2023 1:59 am
Sat May 13, 2023 3:59 pm
; Gimp Script-Fu exports brush .gbr as .png with the idea to import .png in PhotoShop to build brush .abr
(define (Export-gbr-to-png fileGbr) ; Export brush .gbr as .png
(let* ( (vPath (PathSplit fileGbr)) ; See KodiSave.scm
(pathPic (vector-ref vPath 1)) ; 0-based element in the vector
(filename (vector-ref vPath 2))
(lstFile (strbreakup filename ".")) ; split the filename into the basename and the fileExt
(basename (car lstFile))
(filePng (string-append pathPic DIR-SEPARATOR basename ".png"))
(imgPng (car (gimp-image-new 1 1 GRAY)))
(layPng (car (gimp-layer-new imgPng 1 1 GRAY-IMAGE "layer main" 100 LAYER-MODE-NORMAL-LEGACY)))
(imgGbr (car (gimp-file-load-layer 1 imgPng fileGbr))) ; load the brush .gbr
)
(gimp-image-insert-layer imgPng layPng 0 0) ; top of layer stack
(gimp-image-insert-layer imgPng imgGbr 0 0) ; insert .brush as layer
(script-fu-util-image-resize-from-layer imgPng imgGbr) ; resize .png to the brush size
(gimp-layer-resize-to-image-size layPng) ; also its layer
(set! layPng (car (gimp-image-flatten imgPng))) ; merge layer .png and layer .gbr
(file-png-save RUN-NONINTERACTIVE imgPng layPng filePng filePng 0 9 0 0 0 0 0) ; save as .png
(gimp-image-clean-all imgPng) ; clean-up
(gimp-image-delete imgPng) ; you can close the exported .png
(displayln (string-append "Export-gbr-to-png SUCCESSFULLY exported \"" basename ".gbr\" to " filePng))
) )
; (PathSplit "")
; Error: 4500 PathSplit: the path cannot be empty
; (PathSplit "C")
; Error: 4510 PathSplit: the path should have more than one character
; (PathSplit "NoDrive")
; Error: 4520 PathSplit: the path contains an unsupported separator of folders
; (PathSplit "C:")
; #("C:" "" "")
; (PathSplit "C:\\")
; #("C:" "" "")
; (PathSplit "C:\\Tool\\Gimp\\forum\\GimpChat\\SaveXcf-ExportPng")
; #("C:" "C:\\Tool\\Gimp\\forum\\GimpChat" "SaveXcf-ExportPng")
; (PathSplit "C:\\Tool\\Gimp\\forum\\GimpChat\\SaveXcf-ExportPng\\")
; #("C:" "C:\\Tool\\Gimp\\forum\\GimpChat" "SaveXcf-ExportPng")
; (PathSplit "C:\\Tool\\Gimp\\forum\\GimpChat\\SaveXcf-ExportPng\\_GamerOfThrone1.png")
; #("C:" "C:\\Tool\\Gimp\\forum\\GimpChat\\SaveXcf-ExportPng" "_GamerOfThrone1.png")
; (PathSplit "C:\Tool\Gimp\forum\GimpChat\SaveXcf-ExportPng\TV Shows\Gamer of Throne (2011)\_GamerOfThrone1.png")
; Error: 4520 PathSplit: the path contains an unsupported separator of folders
; (PathSplit "C:/Tool/Gimp/forum/GimpChat/SaveXcf-ExportPng/TV Shows/Gamer of Throne (2011)/_GamerOfThrone1.png")
; Error: 4520 PathSplit: the path contains an unsupported separator of folders
; Split a full path returning a vector containing: the drive such as "C:", the parent folder and the basename:
; If the path ends by a filename, the basename if this filename. Otherwise the basename is the last folder of the path.
; string
(define (PathSplit path)
(let* ( (lenDir (string-length path)))
(if (zero? lenDir) (throw "4500 PathSplit: the path cannot be empty"))
(if (< lenDir 2) (throw "4510 PathSplit: the path should have more than one character"))
(let* ( (idxLast (- lenDir 1)) ; index of the last character in the path
(isLastSep? (char=? (string-ref path idxLast) (string-ref DIR-SEPARATOR 0)))
(strDir (if isLastSep? ; If the path ends with the DIR-SEPARATOR
(substring path 0 idxLast) ; Remove ending DIR-SEPARATOR
path ; else keep the path unchanged
) ) )
(if isLastSep? (set! idxLast (- idxLast 1))) ; Since the last DIR-SEPARATOR has been removed, decrement idxLast
(if (char=? (string-ref strDir idxLast) #\:) ; Does the path end with the drive separator ":"?
(vector strDir "" "") ; The parent of the root folder is the root folder. The current folder is empty
(let* ( (lstPath (strbreakup strDir DIR-SEPARATOR)) ; Otherwise split the path removing each DIR-SEPARATOR
(lstDir (reverse (cdr (reverse lstPath)))) ; remove the last folder from lstPath
(parent (if (zero? (length lstDir))
(throw "4520 PathSplit: the path contains an unsupported separator of folders")
(unbreakupstr lstDir DIR-SEPARATOR)) ; Rebuild the parent without the last folder
)
(basename (carDbg (last lstPath) 'PathSplit1 path)) ; basename is the last string of lstPath
(drive (carDbg lstPath 'PathSplit2 path))
)
(vector drive parent basename) ; return a vector: basename could be either the last folder or the filename.
) ) ) ) )
(Export-gbr-to-png "C:\\Tool\\Gimp\\forum\\GimpChat\\Brush\\Chalk-02-copy.gbr")
Tue May 16, 2023 4:37 am
Tue May 16, 2023 4:40 am