Help with script
This discussion is connected to the gimp-user-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.
This is a read-only list on gimpusers.com so this discussion thread is read-only, too.
| Help with script | XTAL256 | 12 Jan 05:07 |
| Help with script | saulgoode@flashingtwelve.brickfilms.com | 13 Jan 00:39 |
| Help with script | XTAL256 | 13 Jan 11:29 |
| Help with script | XTAL256 | 15 Jan 11:32 |
| Help with script | Mark J. Reed | 15 Jan 15:02 |
| Help with script | XTAL256 | 16 Jan 10:46 |
| Help with script | saulgoode@flashingtwelve.brickfilms.com | 16 Jan 20:25 |
| Help with script | XTAL256 | 17 Jan 06:42 |
| Help with script | saulgoode@flashingtwelve.brickfilms.com | 17 Jan 08:15 |
- postings
- 5
Help with script
Hi all,
I am making a 2D game and i am currently working on variable-width bitmap
fonts to use in the game. I have already written code to load an image
containing the characters and display text on screen in the chosen font but up
until now i have just set the width of each character to be all the same
(fixed-width).
Now i have modified it so that it reads in a list of numbers from a file and sets each character's width to the respective number in the list.
All of that works but i now need a way of getting those numbers so i thought someone might help me make a GIMP script that can do it. Basically, i have an image which contains the characters on a 16x8 grid. I will need to find the first line on the x axis which does not contain all transparent pixels and the last line, relative to the current cell (and will loop through all cells). Then i can calculate the width as last-first. I also need to display/print these widths as text so that i can easily copy/paste to a text file.
Here is a diagram of what i need to do: [img]http://img374.imageshack.us/my.php?image=charwidthhz0.jpg[/img]
Any help would be appreciated (and i would *really* appreciated it if someone
could do it for me :).)
Oh, and i am using GIMP 2.6 on WinXP.
thanks
Help with script
http://flashingtwelve.brickfilms.com/GIMP/Scripts/sg-char-process.scm
Quoting XTAL256 :
Hi all,
I am making a 2D game and i am currently working on variable-width bitmap fonts to use in the game. I have already written code to load an image containing the characters and display text on screen in the chosen font but up
until now i have just set the width of each character to be all the same (fixed-width).Now i have modified it so that it reads in a list of numbers from a file and sets each character's width to the respective number in the list.
All of that works but i now need a way of getting those numbers so i thought someone might help me make a GIMP script that can do it. Basically, i have an image which contains the characters on a 16x8 grid. I will need to find the first line on the x axis which does not contain all transparent pixels and the
last line, relative to the current cell (and will loop through all cells). Then i can calculate the width as last-first. I also need to display/print these widths as text so that i can easily copy/paste to a text file.Any help would be appreciated (and i would *really* appreciated it if someone could do it for me :).)
Oh, and i am using GIMP 2.6 on WinXP.
- postings
- 5
Help with script
http://flashingtwelve.brickfilms.com/GIMP/Scripts/sg-char-process.scm
Cool, thanks. Where did you find that?
- postings
- 5
Help with script
Hi again. I just have one question about the script. Well it's more about
Scheme in general but i couldn't find the answer in any tutorials (i was
probably just looking in the wrong place). Anyway, i want to write a comma to
the file but (write "," file) writes the comma with the quotes included. And
using a character #\, doesn't work either. Is there a special escape code for
printing commas or what?
thanks
Help with script
The comma isn't the problem; there's nothing special about commas in Scheme strings. It's the output function you're using - (write) formats things in Scheme source-code form so they can be (eval)'ed when read back in. To just output some text as text, use (display) instead. For a single comma you could also use (write-char #\,).
On 1/15/09, none wrote:
Hi again. I just have one question about the script. Well it's more about Scheme in general but i couldn't find the answer in any tutorials (i was probably just looking in the wrong place). Anyway, i want to write a comma to
the file but (write "," file) writes the comma with the quotes included. And using a character #\, doesn't work either. Is there a special escape code for
printing commas or what?
thanks--
none
_______________________________________________ Gimp-user mailing list
Gimp-user@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-user
- postings
- 5
Help with script
Sorry, i got another question. I want to find the width of each character by essentially "cropping" the cell. But this bit of code in the script saulgoode gave me:
(gimp-rect-select image x y width height ...) (set! bounds (gimp-selection-bounds image))
just seems to get the width and height of the selection, which is obviously known since it's used to set the selection in the first place!
So is there a function to crop the selection or will i have to copy it to a new layer?
Help with script
Quoting none :
Sorry, i got another question. I want to find the width of each character by essentially "cropping" the cell. But this bit of code in the script saulgoode gave me:
(gimp-rect-select image x y width height ...) (set! bounds (gimp-selection-bounds image))
just seems to get the width and height of the selection, which is obviously known since it's used to set the selection in the first place!
Since the operation mode of 'gimp-rect-select' is CHANNEL-OP-INTERSECT, the resulting selection is only the non-transparent part of all chars that lie within the region of that cell (i.e., the non-transparent part of a single char).
This is the opposite order of what you may have been expecting -- that is, to select a cell and THEN select the non-transparent part of the cell -- but the net result is the same! It was simpler to do it my way because the "Alpha To Selection" function ('gimp-selection-layer-alpha') does not allow for CHANNEL-OP modes.
- postings
- 5
Help with script
Oh, ok. Thanks for clearing that up. What about my other question, outputting a comma to the file?
Help with script
Quoting none :
Oh, ok. Thanks for clearing that up. What about my other question, outputting a comma to the file?
You need to use 'display' instead of 'write', and output the offsets individually (or construct a string using 'string-append'; 'display' only accepts one object at a time).
(if (= (car bounds) 0)
(display "0,0" p)
(begin
(begin
(display (- (cadr bounds) x) p)
(display "," p)
(display (- (cadddr bounds) x) p)
)
)
)
More information about handling Scheme's I/O is available at: http://www.schemers.org/Documents/Standards/R5RS/HTML





