[REBOL] Re: Creating thumbnails [view]
From: carl:cybercraft at: 23-Apr-2004 9:16
On 23-Apr-04, Steven White wrote:
> Good Day, Fountain of REBOL Knowledge,
> The following script reads a big jpeg file and displays it on the
> screen as a 96x96 thumbnail. When I hit the button, it saves that
> image to disk as a 96x96 png thumbnail. I mention this to show that
> the idea can be done (as of course you know). _*_*_*
> REBOL [
> ]
> view layout [
> thumbnail: image 96x96 %ships_1024.jpg
> button 300x25 "save/png to-image thumbnail"
> [save/png %shipspng.png to-image thumbnail alert "done"]
> ]
> _*__*_
> Now, I want to do the same thing, but not in an interactive manner,
> not with a screen. I want a script that will automatically make a
> bunch of thumbnails for a bunch of pictures without any human
> intervention. Can I do that?
> It seems I can't use the "image" key word outside of a layout. If I
> use "to-image," I don't see how I can specify the size. I know how
> to find all the files in a directory, and how to loop through them,
> etc, but I am missing that piece to read a jpeg file, turn it into a
> thumbnail, and write it, outside of a VIEW layout. I have looked at
> the cookbook example "HTML Thumbnail Photo Directory Maker," but
> that also uses an image within a layout.
> Thank you.
Hi Steve.
You can turn a layout into an image just by a...
to-image layout [box red]
so if the layout has your picture in, then you've grabbed it without
needing to view the layout. Add to that an origin of 0x0 to get rid
of the border and your problem becomes quite simple...
for n 1 3 1 [
file: %ships_
picture: load rejoin [file n %.jpg]
thumbnail: to-image layout [
origin 0.0
image 96x96 picture
]
save/png rejoin [file n %.png] thumbnail
]
That's not tested though - but I think it'd work, assuming you've
numbered your files without padding...
--
Carl Read