douzhang8144 2012-09-28 20:47
浏览 54
已采纳

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.

  • 写回答

2条回答 默认 最新

  • dongxin5429 2012-09-29 01:08
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大