google-app-engine - 如何在 Google App Engine 中获取 26 字节的非 JPG 图像的宽度和高度?
问题描述
我想获取存储在谷歌云存储中的图像的宽度和高度,而不将其加载到内存中。
我在 stackoverflow 上找到了答案,说明如果图像类型不是JPEG
,或者TIFF
我们可以通过仅在内存中加载 26 个字节来获取图像的宽度和高度。但我无法想出这样做的方法。
我没有找到任何相关的代码片段或文章。
我还想知道是否可以通过使用动态转换PNG
创建的图像来实现get_serving_url()
。并加载该图像的 26 个字节。
解决方案
好的,我来打针。试试这个:
from google.appengine.api import images
import urllib2
image_url = "http://....."
req = urllib2.Request(image_url, headers={'Range': 'bytes=0-30'})
resp = urllib2.urlopen(req)
image_bytes = resp.read()
image = images.Image(image_bytes)
print image.width
print image.height
resp.close()
推荐阅读
- android - 无法在华为设备上为 H264 编码视频设置远程 SDP 报价
- mysql - 使用 Laravel Eloquent 模型查询多个表关系
- python - 如果 sql 有日期条件,pyodbc 结果返回空
- javascript - 触发缓存以确保数据正确问题 - swr 挂钩 - next.js(使用打字稿)
- webix - 带有水平滚动条的树表
- java - 如果连接丢失,我想显示以前的数据而不是空列表
- docker - docker run --entrypoint "python /path/to/file.py" 导致“没有这样的文件或目录:未知。” 错误
- python - 如何在我的 Django+drf-yasg 项目中使用 editor.swagger.io 中的 swagger.json?
- ubuntu - 在 ubuntu linux 中以 root 权限运行 VS Code 不再起作用
- python - 来自分组数据的 2×2 热图矩阵可视化