smallest filesize for transparent single pixel image

前端 未结 11 1556
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-12 13:03

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

相关标签:
11条回答
  • 2020-12-12 13:34

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

    0 讨论(0)
  • 2020-12-12 13:35

    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 32 bytes. But you can "hack" the specification and have a 26-28 byte, 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.

    0 讨论(0)
  • 2020-12-12 13:39

    To expand on Jacob's byte array answer, i generated the c# byte array for a transparant 1x1 gif I made in photoshop.

    static readonly byte[] TrackingGif = { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00, 0x01, 0x00, 0x81, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0xff, 0x0b, 0x4e, 0x45, 0x54, 0x53, 0x43, 0x41, 0x50, 0x45, 0x32, 0x2e, 0x30, 0x03, 0x01, 0x01, 0x00, 0x00, 0x21, 0xf9, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x08, 0x04, 0x00, 0x01, 0x04, 0x04, 0x00, 0x3b};
    
    0 讨论(0)
  • 2020-12-12 13:45

    Checkout this blank.gif file (43 bytes). Less than 49 :D

    0 讨论(0)
  • 2020-12-12 13:50
    • 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
    
    0 讨论(0)
提交回复
热议问题