views:

334

answers:

6

I'm looking for the smallest (in terms of filesize) transparent 1 pixel image.

Currently I have a gif of 49 bytes which seems to be the most popular.

But I remember many years ago having one which was less than 40 bytes. Could have been 32 bytes.

Can anyone do better? Graphics format is no concern as long as modern web browsers can display it and respect the transparency.

UPDATE: OK, I've found a 42 byte transparent single pixel gif: http://bignosebird.com/docs/h3.shtml

UPDATE2: Looks like anything less than 43 bytes might be unstable in some clients. Can't be having that.

+1  A: 

http://www.maproom.co.uk/0.gif Is 43 bytes, shaves a little bit.

Dested
Don't forget the few bytes you shave off the headers too because the filename is slightly shorter :-)
Sander Rijken
+4  A: 

http://commons.wikimedia.org/wiki/File:Blank.gif 43 bytes. Not 49 :D

gmunkhbaatarmn
+2  A: 
  • See: http://www.google-analytics.com/__utm.gif, 35B

  • Alternative in Perl (45B):

    ## tinygif
    ## World's Smallest Gif
    ## 35 bytes, 43 if transparent
    ## Credit: http://www.perlmonks.org/?node_id=7974
    
    
    use strict;
    my($RED,$GREEN,$BLUE,$GHOST,$CGI);
    
    
    ## Adjust the colors here, from 0-255
    $RED   = 255;
    $GREEN = 0;
    $BLUE  = 0;
    
    
    ## Set $GHOST to 1 for a transparent gif, 0 for normal
    $GHOST = 1;
    
    
    ## Set $CGI to 1 if writing to a web browser, 0 if not
    $CGI = 0;
    
    
    $CGI && printf "Content-Length: %d\nContent-Type: image/gif\n\n", 
        $GHOST?43:35;
    printf "GIF89a\1\0\1\0%c\0\0%c%c%c\0\0\0%s,\0\0\0\0\1\0\1\0\0%c%c%c\1\
        +0;",
        144,$RED,$GREEN,$BLUE,$GHOST?pack("c8",33,249,4,5,16,0,0,0):"",2,2,4
    +0;
    

Run it ...

$ perl tinygif > tiny.gif
$ ll tiny.gif
-rw-r--r--  1 stackoverflow  staff    45B Apr  3 10:21 tiny.gif
The MYYN
Copy and paste didn't work for me (identify: Corrupt image). Probably your formatting...? Also the code comment says 35/43 bytes but your output says 45 bytes.
zaf
+2  A: 

You shouldn't really use "spacer gifs". They were used in the 90s; now they are very outdated and they have no purpose whatsoever, and they cause several accessibility and compatibility problems.

Use CSS.

Andreas Bonini
+1 best answer so far :-)
Sander Rijken
I suppose this is still used as tracking images (to track for example how much html emails are 'opened'). Very doubtful use though...
ChristopheD
@ChristopheD - and blocked (for many years now) by default in all sensible email clients, so basically pointless even for that dubious use.
Daniel Earwicker
A: 

I remember once, a long time ago, I tried to create the smallest gif possible. If you follow the standard, If I remember correctly, the size is 32bits. But you can "hack" the specification and have a 26-28 bit, that will show in most browsers. This GIF is not entirely "correct" but works, sometime. Just use a GIF header specification and a HEX editor.

Ross
+1  A: 

Here is what I use in a C# byte array (avoids file access)

static readonly byte[] TrackingGif = { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x1, 0x0, 0x1, 0x0, 0x80, 0x0, 0x0, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0, 0x2c, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x1, 0x0, 0x0, 0x2, 0x2, 0x44, 0x1, 0x0, 0x3b };

In asp.net MVC this can be returned like this

return File(TrackingGif, "image/gif");
Jacob
Yes, thats the idea. How many bytes do you have? Sorry, I'm to lazy to count right now :)
zaf