Skip to content

Instantly share code, notes, and snippets.

@yawo
Last active November 13, 2016 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yawo/8059f2f3b2906b6349ab5254b8a1d04a to your computer and use it in GitHub Desktop.
Save yawo/8059f2f3b2906b6349ab5254b8a1d04a to your computer and use it in GitHub Desktop.
;data
; extract basename without ext
(define (drop-ext str)
(unbreakupstr (butlast (strbreakup str ".")) ".")
)
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
( define ( script-fu-caption sourceDirectory )
( let*
(
; Declare and Init local variables
( returnVal #f )
; Guess host OS based on directory path separator
( isLinux ( >
( length ( strbreakup sourceDirectory "/" ) )
( length ( strbreakup sourceDirectory "\\" ) ) ) )
; Form path/file patternSource based on OS
( patternSource ( if isLinux
( string-append sourceDirectory "/*.[jJ][pP][gG]" )
( string-append sourceDirectory "\\*.[jJ][pP][gG]" ) ) )
; List of files to be converted formatted for current Host
; O/S
( filelistSource ( cadr ( file-glob patternSource 1 ) ) )
; Place holders for image variables - updated per image
( theImage 0 )
( theOrigLayer 0 )
( theBgLayer 0 )
( currentData '())
( theDrawable 0 )
( currentFile "" )
( baseName "" )
( fontname "Apple SD Gothic Neo")
( fontname1 "Apple SD Gothic Neo Bold")
( fontname2 "Apple SD Gothic Neo Light")
( data (list
'("11110001" "L'Abidjanais" "37" "homme-chemises-chemise-abidjanais" )
'("22220001" "Collier perle accra" "26" "femme-colliers-accra" )
'("11111101" "Collier ébène Africa " "30" "homme-accessoires-collier-africa" )
'("22220002" "Collier perle aissatou" "28" "femme-colliers-aissatou" )
'("11111102" "Bracelet ébène Akan" "8" "homme-accessoires-bracelet-akan" )
'("22220003" "Collier perle aneho" "32" "femme-colliers-aneho" )
'("11111103" "Collier ébène GYE NYAME" "30" "homme-accessoires-homme-collier-ashanti" )
'("22220004" "Collier perle bamileke bleu" "34" "femme-colliers-bamileke.bleu" )
'("22220005" "Collier perle bamileke multi" "35" "femme-colliers-bamileke.multi" )
'("22220006" "Collier perle bamileke rouge" "36" "femme-colliers-bamileke.rouge" )
'("22220007" "Collier perle bamileke vert" "37" "femme-colliers-bamileke.vert" )
'("11110002" "King Behanzin " "37" "homme-chemises-chemise-behanzin" )
'("22220008" "Collier perle bineta" "23" "femme-colliers-bineta" )
'("11110003" "Boby Marley" "37" "homme-chemises-chemise-bobmarley" )
'("22221101" "Boucle d'oreille Ankh" "8" "femme-accessoires-boucle-ankh" )
'("22221102" "Boucle d'oreille Cauris" "8" "femme-accessoires-boucle-cauris" )
'("22221103" "Boucle d'oreille Miss ébène" "8" "femme-accessoires-boucle-missebene" )
'("22221104" "Boucle d'oreille Ghana" "8" "femme-accessoires-boucle-ghana" )
'("22221105" "Boucle d'oreille LookMe" "8" "femme-accessoires-boucle-lookme" )
'("22221106" "Boucle d'oreille Terroir" "8" "femme-accessoires-boucle-terroir" )
'("22221107" "Boucle d'oreille Togo" "8" "femme-accessoires-boucle-togo" )
'("22221108" "Boucle d'oreille Lome Love " "8" "femme-accessoires-boucle-togovi" )
'("11111110" "Cartable cuir Black Cross" "30" "homme-accessoires-cartable-blackcross" )
'("11111109" "Cartable cuir Togo" "30" "homme-accessoires-cartable-togo" )
'("22220009" "Collier perle cleopatra blancnoir" "24" "femme-colliers-cleopatra.blancnoir" )
'("22220010" "Collier perle cleopatra bleu" "36" "femme-colliers-cleopatra.bleu" )
'("22220011" "Collier perle cleopatra jaunenoir" "36" "femme-colliers-cleopatra.jaunenoir" )
'("22220012" "Collier perle cleopatra light jaune" "35" "femme-colliers-cleopatra.light.jaune" )
'("22220013" "Collier perle cleopatra light noir" "35" "femme-colliers-cleopatra.light.noir" )
'("22220014" "Collier perle cleopatra light orange" "35" "femme-colliers-cleopatra.light.orange" )
'("22220015" "Collier perle cleopatra light vert" "35" "femme-colliers-cleopatra.light.vert" )
'("22220016" "Collier perle cleopatra orange" "36" "femme-colliers-cleopatra.orange" )
'("22220017" "Collier perle cleopatra rougenoir" "30" "femme-colliers-cleopatra.rougenoir" )
'("22220018" "Collier perle cleopatra rougenoir2" "35" "femme-colliers-cleopatra.rougenoir2" )
'("11110004" "Congo Love" "37" "homme-chemises-chemise-congolove" )
'("22220019" "Collier perle kin" "27" "femme-colliers-kin" )
'("22220020" "Collier perle lomeLove" "27" "femme-colliers-lomelove" )
'("22220021" "Collier perle lome sensation" "27" "femme-colliers-lomesensation" )
'("22220022" "Collier cuir makeba" "20" "femme-colliers-makeba" )
'("11111104" "Collier ébène guerrier Massaï" "30" "homme-accessoires-homme-collier-massai" )
'("11111105" "Collier et Bracelet Mina" "35" "homme-accessoires-homme-collier-bracelet-mina" )
'("22220023" "Collier perle moba" "33" "femme-colliers-moba" )
'("11110005" "K Nkrumah" "37" "homme-chemises-chemise-nkrumah" )
'("11110006" "Osei Tutu" "37" "homme-chemises-chemise-oseitutu" )
'("11111111" "Bracelet ebene Ouidah" "8" "homme-accessoires-bracelet-ouidah" )
'("11111106" "Bracelet panafricain" "8" "homme-accessoires-bracelet-panafricain" )
'("11111107" "Bracelet peace boy" "7" "homme-accessoires-bracelet-peaceboy" )
'("22220024" "Collier perle poku" "27" "femme-colliers-poku" )
'("22221109" "Sac Dashiki style" "34" "femme-accessoires-sac-dashiki" )
'("22221112" "Sac Pagne" "35" "femme-accessoires-sac-pagne" )
'("11110007" "Le Samory" "37" "homme-chemises-chemise-samory" )
'("22221110" "Sandale Mama Africa" "13" "femme-accessoires-sandale-africa" )
'("22221111" "Sandale Tradition Era" "13" "femme-accessoires-sandale-tradition" )
'("11111108" "Collier Soudiata Keita" "32" "homme-accessoires-homme-collier-soudiata" )
'("22220025" "Collier perle sweetHoney rouge" "23" "femme-colliers-sweethoney.rouge" )
'("11110008" "Veste Choco Black" "50" "homme-chemises-veste-chocoblack" )
))
( dataIterator data )
) ; End declaration of Local Variables
;
; Run if images closed, message if not.
( if ( < 0 ( car ( gimp-image-list ) ) )
( gimp-message "Close open Images & Rerun" )
( begin
;
; Run within scope of let* and local variables
; 'baseName' is filename without .jpg extension
; 'outFilename' is filename with .xcf extension
; Step through each file in list with while loop.
( while ( not ( null? filelistSource ) )
( set! currentFile ( car filelistSource ) )
( set! currentData (car dataIterator))
; Get open and get Image ID of current file
( set! theImage
( car ( gimp-file-load RUN-NONINTERACTIVE
currentFile currentFile ) ) )
( begin
;; --------------------------------------
(set! theOrigLayer (vector-ref (cadr (gimp-image-get-layers theImage)) 0))
(gimp-text-fontname theImage theOrigLayer 10 10 "Collection FASHIONAFRO 2016 | fashionafro.contact@gmail.com " 0 TRUE 14 0 fontname2)
(gimp-text-fontname theImage theOrigLayer 10 28 (cadr currentData) 0 TRUE 22 0 fontname1);name
(gimp-text-fontname theImage theOrigLayer 10 57 (string-append "@ " (caddr currentData) " €") 0 TRUE 15 0 fontname);prix
(gimp-text-fontname theImage theOrigLayer 70 60 (string-append "(" (car currentData) ")") 0 TRUE 10 0 fontname2);sku
(gimp-text-fontname theImage theOrigLayer 10 78 (string-append "www.fashionafro.com/" (cadddr currentData)) 0 TRUE 12 0 fontname2);link
; Get / set Drawable ID, need it for file save.
( set! theDrawable ( car ( gimp-image-merge-visible-layers theImage 0 ) ) )
; Save file
( gimp-file-save RUN-NONINTERACTIVE theImage theDrawable currentFile currentFile )
;; --------------------------------------
) ; End begin
( gimp-image-delete theImage )
; Update while loop iteration parameter
(set! filelistSource ( cdr filelistSource ) )
(set! dataIterator (cdr dataIterator))
) ; End while
); End outer begin
) ; End outer if
( set! returnVal #t )
) ; End let*
) ; End define
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
( script-fu-register "script-fu-caption" ; Function Name
"1 ) Caption JPG (Directory)" ; Menu Label
"This script is an interactive script to add Caption on all of the jpegs
in a source directory. The script is designed to be run WITHOUT ANY IMAGE
LOADED. Runs from GIMP shell in Linux and Windows."
"Yawo KPOTUFE" ; Author
"2016, Yawo KPOTUFE" ; Copyright
"November 2016" ; Creation Date
"" ; Valid Image Type - No Image required
; We actually don't want any images open when we run this
; script, so it must be available from the menu when an
; image is not loaded. This script will determine the IDs
; of the Image and Drawable itself rather than having them
; passed as parameters.
; Interactive widgets
SF-DIRNAME "JPG Originals (source) Directory" ""
) ; End script-fu-register
( script-fu-menu-register
"script-fu-caption" "<Image>/Yawo/Caption")
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment