Noob wants to render dynamic png file

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Noob wants to render dynamic png file

johnhwoods
Hi Guys,

Very new to Seaside (<24h) but it looks fantastic.  I'd like to serve a page with a dynamically created .png file - a callback fires some code to generate a .png, but I have no idea how to serve it back.  All the image serving I have been able to do is image files that are either on a web server or already in a FileLibrary.  Can any kind soul please help me?  Many thanks...
Reply | Threaded
Open this post in threaded view
|

Re: Noob wants to render dynamic png file

jgfoster
Hi John,

Welcome to Seaside. I believe that http://comments.gmane.org/gmane.comp.lang.smalltalk.squeak.seaside/21710 contains an answer to your question.

James Foster
http://seaside.gemstone.com/tutorial.html

On Jul 16, 2011, at 2:58 PM, johnhwoods wrote:

> Hi Guys,
>
> Very new to Seaside (<24h) but it looks fantastic.  I'd like to serve a page
> with a dynamically created .png file - a callback fires some code to
> generate a .png, but I have no idea how to serve it back.  All the image
> serving I have been able to do is image files that are either on a web
> server or already in a FileLibrary.  Can any kind soul please help me?  Many
> thanks...
>
> --
> View this message in context: http://forum.world.st/Noob-wants-to-render-dynamic-png-file-tp3672518p3672518.html
> Sent from the Seaside General mailing list archive at Nabble.com.
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Noob wants to render dynamic png file

Lukas Renggli
In reply to this post by johnhwoods
Welcome! This is described here:
http://book.seaside.st/book/in-action/serving-files/images

Lukas

On Saturday, 16 July 2011, johnhwoods <[hidden email]> wrote:

> Hi Guys,
>
> Very new to Seaside (<24h) but it looks fantastic.  I'd like to serve a page
> with a dynamically created .png file - a callback fires some code to
> generate a .png, but I have no idea how to serve it back.  All the image
> serving I have been able to do is image files that are either on a web
> server or already in a FileLibrary.  Can any kind soul please help me?  Many
> thanks...
>
> --
> View this message in context: http://forum.world.st/Noob-wants-to-render-dynamic-png-file-tp3672518p3672518.html
> Sent from the Seaside General mailing list archive at Nabble.com.
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>

--
Lukas Renggli
www.lukas-renggli.ch
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Noob wants to render dynamic png file

johnhwoods
In reply to this post by jgfoster
Hi James, Lukas -

Thanks very much for the quick replies.  I think the main problem is probably that I'm trying to run before I can walk, so I may not have been clear enough in my question - but the two replies, taken together, showed me what to do.

James pointed me at this:  
MyWAComponent>>#'returnCSV'
        | response |
        response := WAResponse
                document: self asCSV
                mimeType: (WAFileLibrary mimetypeFor: 'csv')
                fileName: self caption , ' (' , DateAndTime now printString , ').csv'.
        response doNotCache.
        self session returnResponse: response.
This enabled me to put an anchor 'Get the .png' which, when clicked, returned the image.  Not quite what I wanted, because I wanted it displayed on the page and not offered as a download when a link was clicked.   But it did show me how to set up a MIME document.

Lukas pointed me at this:
ComponentWithForm>>renderContentOn: html
    html image form: (EllipseMorph new
       color: Color orange;
       extent: 200 @ 100;
       borderWidth: 3;
       imageForm)
Unfortunately I don't have WAImage>form: (is it Pharo-specific?)  but I could combine this with James' help to give me this:
MyWAComponent>>renderContentOn: html
    html image width: 400; document: self getPngBytes mimeType: 'image/png' fileName: 'output.png'.
    html horizontalRule.
    (html anchor) callback: [self prev]; with: 'previous image'.
    html space.
    (html anchor) callback: [self next]; with: 'next image'.
...where prev and next decrement/increment a counter which determines what bytes are served by getPngBytes.  Hope I have done the right thing design-wise but it seems to work.  Thanks again for your very useful and quick responses.

John