|
[Image-SIG] Help with PIL image.tostring
http://mail.python.org/pipermail/image-sig/2007-May/004444.html # coding: shift_jis
#import sqlite3
#import pickle import base64 import StringIO import Image, ImageDraw im=Image.open("chojamachi5c.jpg") #size:278*361 pixel draw=ImageDraw.Draw(im) poslistxy = [(50,50),(100,200),(200,200),(200,100)]
draw.polygon(poslistxy,outline='rgb(128,128,128)',fill='rgb(192,192,192)') f = StringIO.StringIO()
im.save(f, "JPEG") data = f.getvalue() base64data = base64.b64encode(data)
f2 = open('datafile', 'w') #データベースのつもり f2.write(base64data) f2.close() -------
<?php
header("Content-type: image/jpeg"); $file = 'c:\python26\datafile'; $imgtext = file_get_contents($file); //データベースから $imgbin = base64_decode($imgtext); $image = imagecreatefromstring($imgbin); imagejpeg($image); imagedestroy($image); ?>
----
chojamachi5c,33KB
datafile,43KB 33 * 1.3 = 43 ← 完璧!
|

- >
- コンピュータとインターネット
- >
- コンピュータ
- >
- ソフトウェア






f = StringIO.StringIO()
im.save(f, "JPEG")
data = f.getvalue()
できた!
2010/8/19(木) 午後 9:31 [ curonikeru ]