PNG文件验证 [英] PNG file validation

查看:118
本文介绍了PNG文件验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Flash网页应用程序,它会显示用户提交的PNG文件。文件上传到通过一些API服务器显示之前。我想,以确保没有坏的文件投放到Flash中,这里的坏是完全不确定的。有没有一种方法来验证PNG文件对PNG规范(这将赶上损坏的文件)?或者在处理不受信任的图像文件,任何最好的初步实践?我只需要处理PNG,所以JPG,GIF等的支持是必要的。语言大多没有关系,但我想preFER Python的解决方案。这是一个Unix网络服务器。

I have a Flash web app which displays user submitted PNG files. Files are uploaded to the server via some API prior to being displayed. I'd like to make sure no "bad" files are served to Flash, where "bad" is entirely unspecific. Is there a way to validate PNG files against the PNG specs (this would catch corrupted files)? Or any best pratice on dealing with untrusted image files? I only need to handle PNG, so JPG, GIF etc. support is necessary. Language mostly does not matter, though I'd prefer Python solutions. This is on a Unix webserver.

谢谢,西门

推荐答案

我会建议你使用Python和PIL(Python图像库这样做):

I would suggest you use Python and PIL (Python Imaging Library to do this):

from PIL import Image

v_image = Image.open(file)
v_image.verify()

捕获任何异常......

Catch any exceptions...

这篇关于PNG文件验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆