[enh] Form>>writeGIFFileNamed:

Lawrence Press lnp at ix.netcom.com
Tue Nov 16 04:58:31 UTC 1999


> There is a writeBMPFileNamed: in Form, but I often want snapshots in
> GIF format.  So I wrote a short bon mots to provide similar
> functionality for GIF.  (I keep (Form fromUser) writeGIFfileNamed:
> 'snapshot.gif' in my Do menu.)  Finding myself filing it in for the
> umpteenth time, I thought someone else might find it useful.

You betcha it's useful; it's one step toward making PWS into Squeak's third
GUI, an alternative to MVC and Morphic (assuming we actually need such a
thing).

While you're at it, consider something like writeGIFStream i.e. write the
Form to a WriteStream, and return contentsOfEntireFile (or perhaps just the
WriteStream itself) without bothering to write to disk.
GIFReadWriter>>putForm:onStream: does more-or-less what Form>>writeGIFStream
would do; GIFReadWriter>>putForm:onFileNamed: does essentially what Mark's
method Form>>writeGIFfileNamed: does.

This sort of thing should be useful in web-inizing traditional applications
e.g. rather than display graphical output as an instance of some Form in
MVC, put <? SomeForm new loadItWithStuff writeGIFStream ?> on a page of your
Swiki; if you go about it the right way, your form will display as an image
on the web page. (If you go about it the WRONG way, you get your GIF as a
string of ASCII characters.)

As a simple example, consider:

SomeAppropriateClass>>testImage
"Generate an arbitrary test Form, write it out as a GIF stream, and return
its contents"

 | form xtnt stream |
 xtnt _ 300 at 300.
 form _ (Form extent: xtnt depth: Display depth)
  fromDisplay: (Rectangle origin: 50 at 50 extent: xtnt).
 stream _ (WriteStream with: '0' asByteArray) reset.
 GIFReadWriter putForm: form onStream: stream.
 ^stream contentsOfEntireFile.

With the corresponding Form method, we could rewrite this as something like:

| xtnt |
 xtnt _ 300 at 300.
 ^(Form extent: xtnt depth: Display depth)
      fromDisplay: (Rectangle origin: 50 at 50 extent: xtnt);
      writeGIFStream.

Now put <? SomeAppropriateClass new testImage ?> all by itself in a file in
the \Server\embedded subdirectory of your Swiki, and link to it from some
other page. POOF! a piece of Squeak's Display appears in your web browser
(provided you've got the Swiki running), even if Squeak itself is minimized.





More information about the Squeak-dev mailing list