gpt4 book ai didi

python - WSGI- python : How to determine the ** OPENED ** file's image type?

转载 作者:太空宇宙 更新时间:2023-11-04 05:59:56 25 4
gpt4 key购买 nike

图像和一些文本已“发布”到此 wsgi 脚本。

但图像文件没有临时路径或类似 php 中的任何内容。

我手里只有一张图片,已经“打开”了,就像“已打开”一样。

我需要在保存之前找出它是什么类型的图像。

我需要文件中的数据。尺寸..类型..等..

import cgi

def application(environ, start_response):

f = cgi.FieldStorage(environ=environ, fp=environ['wsgi.input'])

if f:
f1 = f['f1'].value
f2 = f['f2'].file.read()

if 'f2' in locals():
f = open('/temp_image/1.png', 'w');f.write(f2);f.close()

start_response('200 OK', [('Content-Type', 'text/html')])
yield 'a'

这行不通:

 a = imghdr.what('f2')

因为

 imghdr.what()

需要一个文件路径。但我没有这样的东西,因为文件尚未保存。

最佳答案

我开始写这个但是@robert-zaremba 已经在这里对这类问题给出了很好的答案:

https://stackoverflow.com/a/14590585/101855

关于python - WSGI- python : How to determine the ** OPENED ** file's image type?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25648286/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com