It is currently Sun Jun 07, 2026 3:07 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Check gimp version
PostPosted: Wed Jul 27, 2011 9:56 am  (#1) 
Offline
Script Coder
User avatar

Joined: Jul 14, 2010
Posts: 697
I know there are changes coming up to the gimp API which may break scripts in 2.7+

I'm hoping to modify my 2.6 scripts to work with 2.8, and to help I created a little helper function to check the gimp version so I can then have the code make the appropriate call.

(define (gimp-version-meets? check)
  (let ((c (map string->number (strbreakup check ".")))
        (v (map string->number (strbreakup (car (gimp-version)) "."))))
  (if (> (car v) (car c)) #t (if (< (car v) (car c)) #f (if (> (cadr v) (cadr c)) #t (if (> (cadr v) (cadr c)) #f (if (>= (caddr v) (caddr c)) #t #f)))))))


There might be more elegant solutions then these nested if statements (Saulgoode?) but this seems to work fine.

So in a script you can use (gimp-version-meets? "2.7.1") and it will return #t if your running version of gimp is version 2.7.1 or later, and then have the appropriate calls made.

-Rob A>

_________________
Image
Fantasy Cartography and Mapping by RobA


Last edited by RobA on Wed Jul 27, 2011 7:36 pm, edited 1 time in total.

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: Check gimp version
PostPosted: Wed Jul 27, 2011 10:08 am  (#2) 
Offline
Global Moderator
User avatar

Joined: May 16, 2010
Posts: 16018
Thanks Rob! :)

_________________
Image


Top
 Post subject: Re: Check gimp version
PostPosted: Wed Jul 27, 2011 10:21 am  (#3) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
Well, to just find out if the version is at least 2.8 (or 2.7+), one could test for:

    (defined? 'gimp-image-get-items)


because that function doesn't exist in current versions ("items" are either drawables or groups of drawables, and there are no groups of drawables in GIMP <= 2.6).

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Last edited by saulgoode on Wed Jul 27, 2011 11:32 am, edited 1 time in total.

Top
 Post subject: Re: Check gimp version
PostPosted: Wed Jul 27, 2011 11:27 am  (#4) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
I think you have a mistake: the second test of the cadr terms should be a less-than rather than a greater than.

Checking 2.7.1 against a gimp-version of 2.6.7 returns #t

edit:
Oops, you're testing (car v) is less than itself


Top
 Post subject: Re: Check gimp version
PostPosted: Wed Jul 27, 2011 1:12 pm  (#5) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
(deleted)


Top
 Post subject: Re: Check gimp version
PostPosted: Wed Jul 27, 2011 3:46 pm  (#6) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
I don't know if it's any more elegant, but here is an alternate solution:

(define (gimp-version-meets? check)
  (let loop ((diffs (map - (map string->number (strbreakup check "."))
                           (map string->number (strbreakup (car (gimp-version)) ".")) ))
             (ok? #t) )
    (if (null? diffs)
      ok?
      (cond
        ((> (car diffs) 0)
          (loop '() #t) )
        ((zero? (car diffs))
          (loop (cdr diffs) ok?) )
        (else
          (loop (cdr diffs) #f) )))))


A shorter version (though not quite so obvious what is happening):
(define (gimp-version-meets? check)
  (let loop ((diffs (map - (map string->number (strbreakup check "."))
                           (map string->number (strbreakup (car (gimp-version)) ".")) )))
    (if (null? (cdr diffs))
      (>= (car diffs) 0)
      (if (zero? (car diffs))
        (loop (cdr diffs))
        (> (car diffs) 0) ))))

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Check gimp version
PostPosted: Wed Jul 27, 2011 7:37 pm  (#7) 
Offline
Script Coder
User avatar

Joined: Jul 14, 2010
Posts: 697
paynekj wrote:
I think you have a mistake: the second test of the cadr terms should be a less-than rather than a greater than.

Checking 2.7.1 against a gimp-version of 2.6.7 returns #t

edit:
Oops, you're testing (car v) is less than itself


oops. thanks, fixed.

-Rob A>

_________________
Image
Fantasy Cartography and Mapping by RobA


Top
 Post subject: Re: Check gimp version
PostPosted: Sat Jul 30, 2011 2:21 pm  (#8) 
Offline
GimpChat Member
User avatar

Joined: Jun 04, 2011
Posts: 254
I don't get it

_________________
Image


Top
 Post subject: Re: Check gimp version
PostPosted: Sat Jul 30, 2011 2:27 pm  (#9) 
Offline
Global Moderator
User avatar

Joined: May 16, 2010
Posts: 16018
The script writers are re-writing their scripts so they will not be deprecated in Gimp-2.8 Alonte. :)

_________________
Image


Top
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group