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条)

报告相同问题?

悬赏问题

  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?