Plot and email diagrams with Go on Google App Engine

234 views
Skip to first unread message

Ingo Jaeckel

unread,
Mar 17, 2014, 10:27:15 PM3/17/14
to golan...@googlegroups.com
Hi,

I want to build a GAE/Go app that does the following:
  1. User opens http://example.com/rest/draw
  2. The request body contains x/y values that should be plotted in a diagram e.g. [[0,1],[1,1],[2,4]]
  3. The app generates an image for the x/y values (using something like plotinum or go-gnuplot)
  4. The app sends an email with the generated image as an attachment (using the GAE Mail API)
There are a couple of challenges:
  • I need a Go plotting library that runs on Google App Engine. My options might be limited since I cannot write to the filesystem.
  • I need a plotting library which can produce the image in memory instead of writing to disk. The raw/base64-encoded data should be attached to an email.
  • Assuming I get the raw image data from a GAE-compatible plotting library, how can I attach it to the email? Can someone share an example that attaches the in-memory image data to the email?
  • Is there a way to use the blob store to store and retrieve images instead of writing to a file system? Is there a way to use existing Go plotting libraries and let them write to the blob store instead of the file system? Ideally all data stays in memory for the duration of the request.
Thanks,
Ingo

nvcnvn

unread,
Mar 17, 2014, 10:46:05 PM3/17/14
to golan...@googlegroups.com
Here is an old example https://code.google.com/p/appengine-go/source/browse/example/moustachio and here is the talk http://blog.golang.org/go-at-google-io-2011-videos
In this example you upload an image and then editit online.

I'm not sure about plotting package, but I think with the Go image pkg (http://golang.org/pkg/image/) you can do something like:
img := NewSomKindOfImage()
edit(img)

You don't need access filesystem for doing that.

You can write the image to Google Cloud Storage and then use the appengine image service to get a link and send that link with your email.

burns...@gmail.com

unread,
Mar 19, 2014, 6:58:59 PM3/19/14
to golan...@googlegroups.com, plotinum...@googlegroups.com
Hi Ingo,

Plotinum can write plots to io.Writers (see the comment here: https://code.google.com/p/plotinum/issues/detail?id=101).  Then, it can save a plot into memory via bytes.Buffer.

I haven't tried Plotinum on AppEngine, but I would hope it works with little changes, if any.  You may run into problems loading the font data, which currently sits on the file system, but perhaps that will be OK since it is static.  If you try it out, please let me know the results (email plotinum...@googlegroups.com, CCed on this message).  If it doesn't work, I would be happy to look at patches that make it compatible with AppEngine.



Best,
Ethan

Ingo Jaeckel

unread,
Mar 20, 2014, 11:34:10 AM3/20/14
to burns...@gmail.com, golan...@googlegroups.com, plotinum...@googlegroups.com
Hi Ethan,

thanks! That sounds awesome!

About #1 and #2 are pretty straightforward using the http, strings, and json packages.
About #3: I'd prefer plotinum over the Go image package because of the higher level of abstraction.
About #4: Can someone share an example that sends an email with the GAE Mail API with an image attached?

Thanks,
Ingo


--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/u7gxdkSAGnI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ingo Jaeckel

unread,
Apr 3, 2014, 5:52:12 PM4/3/14
to golan...@googlegroups.com, golan...@googlegroups.com, plotinum...@googlegroups.com, burns...@gmail.com
For future reference, there is a related question about #3 on stackoverflow: http://stackoverflow.com/questions/10776103/golang-emailing-an-image-stored-as-a-google-appengine-blobstore-blob. The author suggests to get the attachment out of GAE's blobstore. I could do the same with Go on GAE if the plotting library can write into the blobstore.

Thanks,
Ingo

On Thursday, March 20, 2014 11:34:10 AM UTC-4, Ingo Jaeckel wrote:
Hi Ethan,

thanks! That sounds awesome!

About #1 and #2 are pretty straightforward using the http, strings, and json packages.
About #3: I'd prefer plotinum over the Go image package because of the higher level of abstraction.
About #4: Can someone share an example that sends an email with the GAE Mail API with an image attached?

Thanks,
Ingo
On Wed, Mar 19, 2014 at 6:58 PM, <burns...@gmail.com> wrote:
Hi Ingo,

Plotinum can write plots to io.Writers (see the comment here: https://code.google.com/p/plotinum/issues/detail?id=101).  Then, it can save a plot into memory via bytes.Buffer.

I haven't tried Plotinum on AppEngine, but I would hope it works with little changes, if any.  You may run into problems loading the font data, which currently sits on the file system, but perhaps that will be OK since it is static.  If you try it out, please let me know the results (email plotinum-discuss@googlegroups.com, CCed on this message).  If it doesn't work, I would be happy to look at patches that make it compatible with AppEngine.



Best,
Ethan

On Monday, March 17, 2014 10:27:15 PM UTC-4, Ingo Jaeckel wrote:
Hi,

I want to build a GAE/Go app that does the following:
  1. User opens http://example.com/rest/draw
  2. The request body contains x/y values that should be plotted in a diagram e.g. [[0,1],[1,1],[2,4]]
  3. The app generates an image for the x/y values (using something like plotinum or go-gnuplot)
  4. The app sends an email with the generated image as an attachment (using the GAE Mail API)
There are a couple of challenges:
  • I need a Go plotting library that runs on Google App Engine. My options might be limited since I cannot write to the filesystem.
  • I need a plotting library which can produce the image in memory instead of writing to disk. The raw/base64-encoded data should be attached to an email.
  • Assuming I get the raw image data from a GAE-compatible plotting library, how can I attach it to the email? Can someone share an example that attaches the in-memory image data to the email?
  • Is there a way to use the blob store to store and retrieve images instead of writing to a file system? Is there a way to use existing Go plotting libraries and let them write to the blob store instead of the file system? Ideally all data stays in memory for the duration of the request.
Thanks,
Ingo

--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/u7gxdkSAGnI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts+unsubscribe@googlegroups.com.

Ethan Burns

unread,
Apr 4, 2014, 8:14:06 AM4/4/14
to Ingo Jaeckel, golan...@googlegroups.com, plotinum...@googlegroups.com
Hi Ingo,

As I mentioned, Plotinum can write to anything implementing the io.Writer interface.  I don't know much about the blobstore.  If it can take []bytes then you should be OK writing the plot to a bytes.Buffer---it implements io.Writer.


Ethan

Ingo Jaeckel

unread,
Apr 4, 2014, 5:21:08 PM4/4/14
to Ethan Burns, golan...@googlegroups.com, plotinum...@googlegroups.com
Hi Ethan,

I have seen Plot.Save() being used in the examples. I cannot use .Save() since it's expecting a file name name to write to. Which method can I call instead to get the binary data of the image ([]byte) to write to the GAE Datastore/Blobstore?

Thanks,
Ingo

Ethan Burns

unread,
Apr 4, 2014, 5:33:13 PM4/4/14
to Ingo Jaeckel, golang-nuts, plotinum...@googlegroups.com

Replying to all:

Hi Ingo,

See my comment here: https://code.google.com/p/plotinum/issues/detail?id=101

Documenting this is on my todo list (though it's near the bottom).

Hope that helps,
Ethan

Reply all
Reply to author
Forward
0 new messages