It is currently Mon Aug 10, 2026 4:33 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: dir-read-entry that doesn't return a string.
PostPosted: Sat Jul 09, 2011 8:38 am  (#1) 
Offline
GimpChat Member

Joined: Jul 08, 2011
Posts: 7
After the script to create the thumbnail for 1 file worked, I decided to make a version that would create one for every files in a dir like a did for my crop script(but this one was actually 1 file in multiple dir).

For some reason, the filename returned is not a string. I checked to make sure my folder name was valid multiple time and I even wrote it manually in the script but I still get the error that what's returned from dir-read-entry is not a string.

I also made sure that the folder wasn't empty.

Here's the script:
(define (thumb_maker path)
(let* (
(dirlist (dir-open-stream (string-append path DIR-SEPARATOR)))
(input)(output)(image)(width)(height)(q)(r)(x)(y)(drawable)(currentfile)
)

(while (not (eof-object? (set! currentfile (dir-read-entry dirlist)))))
;***********************************************************************
;*Next is where the error happens, with the currentfile var in the string-append function.*
;***********************************************************************
(if (= (file-type (string-append path DIR-SEPARATOR currentfile)) 1)
(begin
(set! input (string-append path DIR-SEPARATOR currentfile))
(set! output (string-append path DIR-SEPARATOR currentfile "_thumb.jpg"))
(set! image (car (file-jpeg-load 1 input output)))
(set! width (car (gimp-image-width image)))
(set! height (car (gimp-image-height image)))

;Set the jpeg quality
(set! q 0.85)
;Set the new height
(set! y 150)
;Calculate the scale ratio
(set! r (/ height y))
;Calculate the new width
(set! x (trunc (/ width r)))
;Resize the image
(gimp-image-scale image x y)
;Update drawable
(set! drawable (car (gimp-image-get-active-drawable image)))
;Save in jpeg
(file-jpeg-save 1 image drawable output output q 0 1 0 "" 0 1 0 0)))
(dir-close-stream dirlist)))


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: dir-read-entry that doesn't return a string.
PostPosted: Sat Jul 09, 2011 12:04 pm  (#2) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
(while (not (eof-object? (set! currentfile (dir-read-entry dirlist)))))

Check the balancing of your parentheses.

I would mention that while currently Script-fu will return the value being assigned as a result of a 'set!' statement, this is not guaranteed by the Scheme language standard (see section 4.1.6). I would propose that you modify your code so as not to rely on the return value.

Personally, I find the named 'let' form to be useful for most looping situations:
(let handle-next-entry ( (currentfile (dir-read-entry dirlist)) )
  (unless (eof-object? currentfile)
    ...
    ...
    ...
    (handle-next entry (dir-read-entry dirlist)) ))



EDITED fix code.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Last edited by saulgoode on Sat Jul 09, 2011 2:27 pm, edited 1 time in total.

Top
 Post subject: Re: dir-read-entry that doesn't return a string.
PostPosted: Sat Jul 09, 2011 1:46 pm  (#3) 
Offline
GimpChat Member

Joined: Jul 08, 2011
Posts: 7
Thanks. Since it's been a while since I wrote a script, I guess I assumed I used one of the function wrong or something. I never noticed the while statement included nothing.

I tried your way of looping and there's something I don't quite get; what kind of expression does it expect at the end of the statement? The only way I managed to make it work is with this:
(handle-next-entry (dir-read-entry dirlist)) )) ))


I would have expected it to either want only "(handle-next-entry)" so that it knows to return to the beginning or "(handle-next-entry (currentfile (dir-read-entry dirlist)))" to repeat the whole expression.

I'll look into removing the set! from my scripts. The source I learned from(forgot what is was) used them so I also did. Thanks(once again) for pointing that out.


Top
 Post subject: Re: dir-read-entry that doesn't return a string.
PostPosted: Sat Jul 09, 2011 2:28 pm  (#4) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
SamKook wrote:
I tried your way of looping and there's something I don't quite get; what kind of expression does it expect at the end of the statement? The only way I managed to make it work is with this:
(handle-next-entry (dir-read-entry dirlist)) )) ))

You are correct. I had erroneously omitted the 'dirlist' argument.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: dir-read-entry that doesn't return a string.
PostPosted: Sat Jul 09, 2011 2:43 pm  (#5) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
SamKook wrote:
I'll look into removing the set! from my scripts. The source I learned from(forgot what is was) used them so I also did. Thanks(once again) for pointing that out.


You don't really need to remove 'set!' statements altogether. I would just avoid treating them as functions.

For example, even though Script-fu will permit you to do the following:

    (set! z (set! y (set! x 0)))

it is not a good idea to do so because the resulting behavior may change in the future (and such an approach may not work with other implementations of Scheme).

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: dir-read-entry that doesn't return a string.
PostPosted: Sat Jul 09, 2011 4:51 pm  (#6) 
Offline
GimpChat Member

Joined: Jul 08, 2011
Posts: 7
saulgoode wrote:
I would just avoid treating them as functions.


K, good to know.


Top
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group