[Seaside] On Forms, PNGs, WAFiles, and ByteArrays
philippe.marschall at gmail.com
Mon Jan 11 06:06:35 UTC 2010
2010/1/11 Robert Sirois <watchlala at hotmail.com>:
> I wrote a simple form to upload images to the server, and I would like to
> create thumbnails for them automatically.
> The way I ended up doing it is as follows:
> | aForm newForm |
> " add original file under name blahblahPng or whatever the image type is
> UGFileLibrary addFileNamed: title,'Png' contents: uploadedFile contents.
> aForm := (PNGReadWriter createAFormFrom: uploadedFile contents) first.
> " create thumbnail and save under name blahblahThumbPng "
> newForm := aForm scaledToSize: (Point x: 50 y: 50).
> " what I would have liked to do here is add the thumbnail to the file
> library "
> " add item to art section "
> UGArt addImage: (
> title: title path: title,'Png') artist: self session user;
> imageForm: aForm; thumbForm: newForm; yourself
> As you can see, I ended up using WAImageTag #form: rather than a url from
> the file library (or server directory, preferably). So what I would like to
> know are two things:
> 1) Forms are big? So throwing them around is cumbersome?
> 2) Is there a way to convert a Form back to a PNG without the whole mime
I haven't tried it but something along those lines should work:
contents: (ByteArray streamContents: [ :stream |
(PNGReadWriter on: stream) nextPutImage: (aForm scaledToSize:
(Point x: 50 y: 50))])
And then simply linking it with:
html image url: UGThumbnailLibrary / (title,'Png')
Note that WAFileLibrary is not intended for production purposes. We
recommend you store them on the file system and let Apache do it's
magic. I can also recommend Smagick for doing the thumbnail. If you
are on Seaside 3.0 you have the option to let the server save uploads
directly to the disk without it hitting the image.
More information about the seaside