का उपयोग करें और इस बात के लिए जनहित याचिका lybrary स्थापित करने के लिए कोई ज़रूरत नहीं है, वहाँ imghdr मानक मॉड्यूल वास्तव में उपयोग के इस तरह के लिए fited है।
http://docs.python.org/library/imghdr.html
import imghdr
image_type = imghdr.what(filename)
if not image_type:
print "error"
else:
print image_type
देखें तो आपको स्ट्रीम से एक छवि है के रूप में आप इस तरह शायद धारा विकल्प का उपयोग कर सकते हैं:
image_type = imghdr.what(filename, incomming_image)
वास्तव में यह (यहां तक कि Pylons में मेरे लिए काम करता अगर मैंने सबकुछ पूरा नहीं किया है): मको टेम्पलेट में:
${h.form(h.url_for(action="save_image"), multipart=True)}
Upload file: ${h.file("upload_file")} <br />
${h.submit("Submit", "Submit")}
${h.end_form()}
अपलोड controler में
:
def save_image(self):
upload_file = request.POST["upload_file"]
image_type = imghdr.what(upload_file.filename, upload_file.value)
if not image_type:
return "error"
else:
return image_type
स्रोत
2009-06-24 18:18:02
यह ऐप इंजन में काम नहीं करेगा: पीआईएल में सी कोड है और इसलिए उपलब्ध नहीं है। छवियों एपीआई (http://code.google.com/appengine/docs/images/) पीआईएल का उपयोग करता है, लेकिन यह stubbed बाहर है। – chryss