django - Generate 1MB image python -
i need generate 1mb image file teste on django. can set image size, not image file size.
image_file = stringio() image = image.new('rgba', size=(4000,4000), color=(256,0,0)) image.save(image_file, 'png')
the simplest way save bmp image, has no compression:
in [1]: image.new('l', (1024, 1024)).save('/tmp/x.bmp') in [2]: !ls -alh /tmp/x.bmp -rw-r--r-- 1 wolever wheel 1.0m jul 13 16:46 /tmp/x.bmp and if need use png, can fill random data:
in [3]: import os in [4]: image.frombytes('l', (1024, 1024), os.urandom(1024*1024)).save('/tmp/x.png') in [5]: !ls -alh /tmp/x.png -rw-r--r-- 1 wolever wheel 1.0m jul 13 16:49 /tmp/x.png
Comments
Post a Comment