如何保存大于90 KB的PNG图像?

问题描述 投票:-1回答:1

我有一个图像,我正在将它们转换为NumPy数组。然后,经过一些处理,我使用save_img命令将那些处理过的图像保存到PNG中。我想知道如何使用下面的代码保存仅大于90KB的图像?我想使用“ save_img”功能

from keras.preprocessing.image import load_img
from keras.preprocessing.image import save_img
from keras.preprocessing.image import img_to_array
# load image as as RGB
img = load_img('bondi_beach.png')
# convert image to a numpy array
img_array = img_to_array(img)
# save the image with a new filename
save_img('bondi_beach_grayscale.png', img_array)
python-3.x python-imaging-library numpy-ndarray tf.keras
1个回答
0
投票

您可以使用以下方法计算图像的权重。

import os
print(os.stat('small_tree.png').st_size/1024,'KB')

一旦有了权重,就可以根据阈值大小写一个条件来保存图像或不保存图像。希望这可以帮助。谢谢

© www.soinside.com 2019 - 2024. All rights reserved.