从Base64字符串获取图像文件大小 [英] Get Image File Size From Base64 String

查看:4166
本文介绍了从Base64字符串获取图像文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个python Web服务。
它调用另一个Web服务来更改配置文件的图片。

I'm working on a python web service. It calls another web service to change the picture of a profile.

它连接到另一个Web服务。
此网络服务只能接受4 MB或更小的图片。

It connects to another web service. This web service can only accept pictures that are 4 MB or smaller.

我会将检查放在第一个网络服务中。
它使用PIL检查base64字符串是否是有效图像。
但是,如何检查base64字符串是否会创建一个4 MB或更小的图像?

I will put the checking in the first web service. It uses PIL to check if the base64 string is a valid image. However, how do I check if the base64 string will create a 4 MB or smaller image?

推荐答案

乘以数据长度为3/4,因为编码将6个字节变为8个。如果结果在4MB的几个字节内,那么你需要计算 = 最后。

Multiply the length of the data by 3/4, since encoding turns 6 bytes into 8. If the result is within a few bytes of 4MB then you'll need to count the number of = at the end.

这篇关于从Base64字符串获取图像文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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