Skip to content

Instantly share code, notes, and snippets.

@Ariex
Created June 26, 2016 12:59
Show Gist options
  • Save Ariex/67bb6f2ad008409ebf4b7f8ae9657621 to your computer and use it in GitHub Desktop.
Save Ariex/67bb6f2ad008409ebf4b7f8ae9657621 to your computer and use it in GitHub Desktop.
Create a transparent gif spacer with specified width and height
public static string GetBase64GifSpacer(int width, int height){
var bwidth = BitConverter.GetBytes(width);
var bheight = BitConverter.GetBytes(height);
var bytes = new byte[] { 0x47,0x49,0x46,0x38,0x39,0x61,bwidth[0],bwidth[1],bheight[0],bheight[1],0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0xF9,0x04,0x01,0x00,0x00,0x00,0x00,0x2C,0x00,0x00,0x00,0x00,bwidth[0],bwidth[1],bheight[0],bheight[1],0x00,0x02,0x02,0x44,0x01,0x00,0x3B };
return "data:image/gif;base64,"+Convert.ToBase64String(bytes);
}
@Ariex
Copy link
Author

Ariex commented Jun 26, 2016

The reason of making this method, is to create a gif spacer image in base64 format with transparent background and dynamic width and height.
demo is available at: https://dotnetfiddle.net/04gsqG

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment