docpicture

André andre.roberge at gmail.com
Tue Oct 14 21:31:26 EDT 2008


On Oct 14, 1:56 pm, bearophileH... at lycos.com wrote:
> 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.

While I agree that embedded images should be as small as possible,
this,
I believe, should be left entirely to the user.  The code sample I
gave
was just a proof of concept - something people asked for on this list.

> For the encoding/decoding you can use str.encode("base64") and
> str.decode("base64"), you don't need to import modules.
>
Good suggestion.

> Bye,
> bearophile

A more complete example is now available at
http://code.activestate.com/recipes/576538/

André

(Of course, now I'll have to include this in Crunchy... ;-)



More information about the Python-list mailing list