It is currently Tue Aug 18, 2026 12:04 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: GIMP 2.6 srcipt fu help needed
PostPosted: Wed Feb 06, 2013 5:02 am  (#1) 
Offline
GimpChat Member

Joined: Feb 06, 2013
Posts: 5
Hi i need help with part of code of script fu.
I have mixed up images in indexed and RGB mode. I want to open image, change to RGB if image is in indexed mode, change hue, save file.

Now everything works beside this missed part:
- if image is indexed convert to RGB, if image is actually in RGB then change hue (finish the script).

This is my script:
(define (change-hue filesNames)
   (let* ((filelist (cadr (file-glob filesNames 1))))
      (while (not (null? filelist))
         (let* (
               ; Pobranie nazwy pliku
               (fileName (car filelist))
               ; Otwarcie pliku:
               (image (car (file-png-load 1 fileName fileName)))
               ; Pobranie warstwy
               (darwable (car (gimp-image-get-active-layer image)))
            )
                                ; Zmiana na RGB
                                (gimp-image-convert-rgb image)
            ; Barwienie
            (gimp-hue-saturation darwable 0 -145 0 0)
            ; Zapis do pliku
            (file-png-save 1 image darwable fileName fileName 1 0 0 0 0 0 0)
         )
         ; Zmiejszenie listy plików o jeden.
         (set! filelist (cdr filelist))
      )
   )
)
(script-fu-register "change-hue"
   "<Image>/Script-Fu/Zmiana odcienia"
   "Otwiera, zmienia odcień i zapisuje plik png."
   "jackq"
   "jackq"
   "Luty 2013"
   ""
   SF-STRING "Pliki:" "E:\\1\\*.png"
)


Can anyone help me with this missed part of code?
Cheers.


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: GIMP 2.6 srcipt fu help needed
PostPosted: Wed Feb 06, 2013 5:33 am  (#2) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
Place the two alternatives within an 'if' statement:
(if (= (car (gimp-image-base-type image)) INDEXED)
  (gimp-image-convert-rgb image)
  (gimp-hue-saturation darwable 0 -145 0 0) )

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: GIMP 2.6 srcipt fu help needed
PostPosted: Wed Feb 06, 2013 6:05 am  (#3) 
Offline
GimpChat Member

Joined: Feb 06, 2013
Posts: 5
Thanks a lot, i put this code, now it look:
(define (change-hue filesNames)
   (let* ((filelist (cadr (file-glob filesNames 1))))
      (while (not (null? filelist))
         (let* (
               ; Pobranie nazwy pliku
               (fileName (car filelist))
               ; Otwarcie pliku:
               (image (car (file-png-load 1 fileName fileName)))
               ; Pobranie warstwy
               (darwable (car (gimp-image-get-active-layer image)))
            )
            (if (= (car (gimp-image-base-type image)) INDEXED)
              (gimp-image-convert-rgb image)
              (gimp-hue-saturation darwable 0 -145 0 0) )
            ; Zapis do pliku
            (file-png-save 1 image darwable fileName fileName 1 0 0 0 0 0 0)
         )
         ; Zmiejszenie listy plików o jeden.
         (set! filelist (cdr filelist))
      )
   )
)
(script-fu-register "change-hue"
   "<Image>/Script-Fu/Zmiana odcienia"
   "Otwiera, zmienia odcień i zapisuje plik png."
   "jackq"
   "jackq"
   "Luty 2013"
   ""
   SF-STRING "Pliki:" "E:\\1\\*.png"
)


Now script convert indexed to rgb - ok
doesn't change hue in converted images, but change hue in original rgb images.


Top
 Post subject: Re: GIMP 2.6 srcipt fu help needed
PostPosted: Wed Feb 06, 2013 8:34 am  (#4) 
Offline
New Member

Joined: Feb 06, 2013
Posts: 3
Isn't it too tricky.


Top
 Post subject: Re: GIMP 2.6 srcipt fu help needed
PostPosted: Wed Feb 06, 2013 9:50 am  (#5) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
jackq1 wrote:
Now script convert indexed to rgb - ok
doesn't change hue in converted images, but change hue in original rgb images.

I was going by this description: "if image is actually in RGB then change hue (finish the script)."

To change the hue on all images, move that filter to be outside the 'if' statement:
            (if (= (car (gimp-image-base-type image)) INDEXED)
              (gimp-image-convert-rgb image) )
            (gimp-hue-saturation darwable 0 -145 0 0)

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: GIMP 2.6 srcipt fu help needed
PostPosted: Wed Feb 06, 2013 10:10 am  (#6) 
Offline
GimpChat Member

Joined: Feb 06, 2013
Posts: 5
Figured it out. Working well. Thanks again. Regards.


Top
 Post subject: Re: GIMP 2.6 srcipt fu help needed
PostPosted: Fri Feb 22, 2013 2:33 pm  (#7) 
Offline
GimpChat Member

Joined: Feb 06, 2013
Posts: 5
One thing more.
How to modify this script to work with all png's placed in folders and subfolders placed in for ex.
SF-STRING "Pliki:" "E:\\1\\any_folder\\any_subfolder\\*.png"


Top
 Post subject: Re: GIMP 2.6 srcipt fu help needed
PostPosted: Fri Feb 22, 2013 10:33 pm  (#8) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
The following procedure can be used to search all directories and subdirectories for a particular wildcard pattern. Although it is kind of basic (it does not, for example, follow symbolic links to other directories), it should work for most situations.

;; 'dir' should be set to the starting directory and must include a trailing slash.
;; 'file-filter' is the file-matching pattern (as employed by the 'file-glob' function)
;;
;; Example:
;;       (set! all-jpegs (recursive-match "/home/saul/images/" "*.jpg"))
;; Return value (a list of strings):
;; ("/home/saul/images/baby.jpg" "/home/saul/images/devil.jpg"
;;  "/home/saul/images/ClippingMasks/GIMPproblem.jpg"
;;  "/home/saul/images/ppp/CN/jnk.jpg" "/home/saul/images/ppp/FN/tmp.jpg"
;;  "/home/saul/images/ppp/FN/tmp1.jpg")
;;

(define (recursive-match dir file-filter)
  (let ((pot-matches (cadr (file-glob (string-append dir file-filter) 1))))
    (let loop ((names (cadr (file-glob (string-append dir "*") 1)))
               (matches nil) )
      (if (null? names)
        matches
        (if (= (file-type (car names)) 2)
          (loop (cdr names)
                (append matches (recursive-match (string-append (car names)
                                                                DIR-SEPARATOR )
                                                 file-filter )))
          (loop (cdr names)
                (if (pair? (member (car names) pot-matches))
                  (cons (car names) matches)
                  matches )))))))

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: GIMP 2.6 srcipt fu help needed
PostPosted: Sun Feb 24, 2013 9:51 am  (#9) 
Offline
GimpChat Member

Joined: Feb 06, 2013
Posts: 5
Thanks. I changed my script. Now look that:
(define (recursive-match "e:\\1\\" "*.png")
   (let ((pot-matches (cadr (file-glob (string-append "e:\\1\\" "*.png") 1))))
      (let loop ((names (cadr (file-glob (string-append "e:\\1\\" "*") 1)))
               (matches nil) )
      (if (null? names)
        matches
        (if (= (file-type (car names)) 2)
          (loop (cdr names)
                (append matches (recursive-match (string-append (car names)
                                                                / )
                                                 "*.png" )))
          (loop (cdr names)
                (if (pair? (member (car names) pot-matches))
                  (cons (car names) matches)
                  matches ))
               ; Open file
               (image (car (file-png-load 1 fileName fileName)))
               ; Get active layer
               (darwable (car (gimp-image-get-active-layer image)))
            )
            ; Convert to RGB and change hue
            (if (= (car (gimp-image-base-type image)) INDEXED)
              (gimp-image-convert-rgb image) )
              (gimp-hue-saturation darwable 0 -180 0 0)
            ; Save file
            (file-png-save 1 image darwable fileName fileName 1 0 0 0 0 0 0)
         )
         ; Decreasing file list by one.
         (set! filelist (cdr filelist))
      )
   )
)
(script-fu-register "change-hue"
   "<Image>/Script-Fu/change-hue"
   "Otwiera, zmienia odcien i zapisuje plik png."
   "jackq"
   "jackq"
   "Luty 2013"
   ""
)


At end of script i have to put SF-STRING? or something else?
This script is for the same job like earlier but i want to this one open/convert/colorize/save all png's in any folder or sublolder placed in E:\1\
Thanks in advance.


Top
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group