Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #21415
| From | Jon Clements <joncle@googlemail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Finding MIME type for a data stream |
| Date | 2012-03-08 18:31 -0800 |
| Organization | http://groups.google.com |
| Message-ID | <30829846.74.1331260282202.JavaMail.geo-discussion-forums@vbai14> (permalink) |
| References | <%U96r.32867$082.25394@newsfe04.iad> <mailman.518.1331244722.3037.python-list@python.org> <3oa6r.31449$L12.8825@newsfe23.iad> <mailman.521.1331247434.3037.python-list@python.org> <yrb6r.35195$zD5.24208@newsfe12.iad> |
On Thursday, 8 March 2012 23:40:13 UTC, Tobiah wrote: > > I have to assume you're talking python 2, since in python 3, strings > > cannot generally contain image data. In python 2, characters are pretty > > much interchangeable with bytes. > > Yeah, python 2 > > > > if you're looking for a specific, small list of file formats, you could > > make yourself a signature list. Most (not all) formats distinguish > > themselves in the first few bytes. > > Yeah, maybe I'll just do that. I'm alowing users to paste > images into a rich-text editor, so I'm pretty much looking > at .png, .gif, or .jpg. Those should be pretty easy to > distinguish by looking at the first few bytes. > > Pasting images may sound weird, but I'm using a jquery > widget called cleditor that takes image data from the > clipboard and replaces it with inline base64 data. > The html from the editor ends up as an email, and the > inline images cause the emails to be tossed in the > spam folder for most people. So I'm parsing the > emails, storing the image data, and replacing the > inline images with an img tag that points to a > web2py app that takes arguments that tell it which > image to pull from the database. > > Now that I think of it, I could use php to detect the > image type, and store that in the database. Not quite > as clean, but that would work. > > Tobiah Something like the following might be worth a go: (untested) from PIL import Image img = Image.open(StringIO(blob)) print img.format HTH Jon. PIL: http://www.pythonware.com/library/pil/handbook/image.htm
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Finding MIME type for a data stream Tobiah <toby@tobiah.org> - 2012-03-08 13:55 -0800
Re: Finding MIME type for a data stream Dave Angel <d@davea.name> - 2012-03-08 17:11 -0500
Re: Finding MIME type for a data stream Tobiah <toby@tobiah.org> - 2012-03-08 14:28 -0800
Re: Finding MIME type for a data stream Dave Angel <d@davea.name> - 2012-03-08 17:56 -0500
Re: Finding MIME type for a data stream Tobiah <toby@tobiah.org> - 2012-03-08 15:40 -0800
Re: Finding MIME type for a data stream Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-03-08 21:04 -0500
Re: Finding MIME type for a data stream Tobiah <toby@tobiah.org> - 2012-03-09 08:40 -0800
Re: Finding MIME type for a data stream Jon Clements <joncle@googlemail.com> - 2012-03-08 18:31 -0800
Re: Finding MIME type for a data stream Tobiah <toby@tobiah.org> - 2012-03-09 09:53 -0800
Re: Finding MIME type for a data stream Tobiah <toby@tobiah.org> - 2012-03-08 14:34 -0800
Re: Finding MIME type for a data stream Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2012-03-09 03:12 +0100
Re: Finding MIME type for a data stream Tobiah <toby@tobiah.org> - 2012-03-09 08:35 -0800
Re: Finding MIME type for a data stream Peter Otten <__peter__@web.de> - 2012-03-09 11:50 +0100
csiph-web