docpicture

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Tue Oct 14 12:56:29 EDT 2008


André:
> Ok, the following is my first attempt at implementing this idea.

I suggest you to change the program you use to encode your images,
because it's 1000 bytes, while with my program the same 256 colors
image needs just 278 bytes:

iVBORw0KGgoAAAANSUhEUgAAABYAAAAeCAMAAAAfOR5kAAAABGdBTUEAAL
GPC/xhBQAAAAd0SU1FB9gKDhAtOfvfKucAAAAYUExURf///wAAADMzM1tb
W4CAgKSkpMDAwP8AAEQE8ZoAAAABdFJOUwBA5thmAAAACXBIWXMAAA50AA
AOdAFrJLPWAAAAdElEQVQoU63Q0QrAIAgFUO/U9f9/vIxqpRIMdqOXQ6lF
RHBhsgAXs4zofXPzTZujlMayRjdmaMZDjXvtEy9FFp75zOXI/pX5n6D/lQ
v1WHnUJarTjGuRxpIxkLHtyIinx4tcy2S694Kjfzn2HDNqYM54H/wB55QF
O+Mp5mAAAAAASUVORK5CYII=

(and it contains just 8 colors, so it can be saved as a 4 bit PNG,
saving even more bytes). Generally I suggest to use as few bits/pixel
as possible, just 1 if possible.
For the encoding/decoding you can use str.encode("base64") and
str.decode("base64"), you don't need to import modules.

Bye,
bearophile



More information about the Python-list mailing list