15
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Python3で画像をBase64エンコーディング

Last updated at Posted at 2016-05-13

WebSocketで画像を送信する時に、Base64でエンコーディングしてから送信するために使ったコードのメモ。
もっと楽な方法はないものかね?

import base64

img_file = 'hoge.jpg'
b64 = base64.encodestring(open(img_file, 'rb').read())
try:
    # Python2                                                                                                                                                          
    print('b64=' + b64)
except TypeError:
    # Python3                                                                                                                                                          
    print('b64=' + b64.decode('utf8'))
15
17
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?