Answer the question
In order to leave comments, you need to log in
How to generate an empty image?
Hello! The frontend uses an empty image (as a placeholder so that the content does not move out when loading images) for lazy load loading of images. There is a service that generates this empty image. Using its API is unwise, because. extra requests from the backend server. How can I generate this empty image using python?
data:image/gif;base64,R0lGODlhZAAyAIAAAP///wAAACH5BAEAAAEALAAAAABkADIAAAJNjI+py+0Po5y02ouz3rz7D4biSJbmiabqyrbuC8fyTNf2jef6zvf+DwwKh8Si8YhMKpfMpvMJjUqn1Kr1is1qt9yu9wsOi8fksvlsKwAAOw==
Answer the question
In order to leave comments, you need to log in
Nagovnokodil what you need. Thanks to all!
image = Image.open("[Путь до изображения]")
image.putalpha(0)
buffer = BytesIO()
image.save(buffer, format='PNG')
buffer.seek(0)
image_bytes = buffer.read()
image_base64 = base64.b64encode(image_bytes).decode('ascii')
put the empty.gif file in the img folder
Or like this
https://jsfiddle.net/vkorotenko/j1bzntaw/
import numpy as np
image = np.zeros((50, 100, 3), np.uint8) # чёрное
image = np.ones((50, 100, 3), np.uint8) * 255 # белое
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question