Skip to content

Instantly share code, notes, and snippets.

@omsobliga
Last active June 13, 2018 04:19
Show Gist options
  • Save omsobliga/f3f8643e733f97d13d3f0a57a7325de4 to your computer and use it in GitHub Desktop.
Save omsobliga/f3f8643e733f97d13d3f0a57a7325de4 to your computer and use it in GitHub Desktop.
保存图片到buffer
### 保存图片到内存
import StringIO
output = StringIO.StringIO()
format = 'PNG' # or 'JPEG' or whatever you want
image.save(output, format)
contents = output.getvalue()
output.close()
### 保存图片到文件
file = 'image.png'
image.save(file_name)
with open(file_name) as f:
image = StringIO.StringIO(f.read())
upload_image(image, file_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment