Advertisement
kxphotographer

画像をbase64URLにして格納するinsert文を出力するスクリプト

Sep 17th, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.41 KB | None | 0 0
  1. import cStringIO, base64
  2. from PIL import Image
  3.  
  4. name = raw_input('name: ')
  5. imagepath = raw_input('path: ')
  6.  
  7. tmp = cStringIO.StringIO()
  8. img = Image.open(imagepath.strip())
  9. img.save(tmp, format='JPEG')
  10. b64 = base64.b64encode(tmp.getvalue())
  11.  
  12. f = open('out.sql', 'a')
  13. f.write("insert into data(name, data) values ('%(name)s', 'data:image/jpeg;base64,%(data)s');\n" % {
  14.         "name": name,
  15.         "data": b64
  16. })
  17. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement