Go + Appengine Blobstore,调整图片上传大小

I'm trying to get my head around Go + Appengine. I have been using Blobstore to store users image uploads. Is there anyway I can download the image from the BlobStore and manipulate it?

Or is there another solution?

The image lib is a bit limited. I would also like to convert others formats to jpeg.

Yes, you can pull a file out of the blobstore and take advantage of the image packages that are included with Go 1, including image/draw and image/jpeg. See The Go image package for an overview and the image/draw blog post. Assuming you already have the BlobInfo for an image you want to manipulate, you can get its raw data by passing the embedded BlobKey to blobstore.NewReader, giving you an io.Reader object. Pass that to e.g. png.Decode to get an image.Image. Do whatever manipulations you like, then to save it back to blobstore, get a Writer from blobstore.Create and hand it to jpeg.Encode. Finally call blobstore.Close and .Key to get a new BlobKey to save in the datastore.

If you want to do even more complex manipulations, there are several pure-Go libraries that you can upload with your app and use with image.Image. See for instance graphics-go and the "Images and Graphics" section of Libraries Written in Go.

I wanted to have a package that will automatically do the magic of optimizing blobstore images. The result can be found at GitHub: https://github.com/TomiHiltunen/GAE-Go-image-optimizer

The algorithm itself is pretty much like Adam Thomason described. This package just hides the ugly bits and automates the process.

You can use it like you would use blobstore.ParseUploads(). What it does is that it runs through the uploaded blobs and optimizes images leaving all other type of blobs untouched. It will also return all the other values passed from blobstore.ParseUploads().