Graphics interchange format
image/gif
Magic Bytes
Offset: 0
47 49 46 38 37 61
The Graphics Interchange Format (GIF) is a bitmap image format developed by CompuServe to facilitate color image exchange across diverse computing platforms. It utilizes lossless LZW compression and supports multi-frame animation, establishing it as a standard for simple graphics, looped video clips, and web-based memes. While significantly limited by a 256-color palette compared to modern alternatives like PNG or WebP, the format remains ubiquitous due to universal browser support.
Validation Code
How to validate .gif files in Python
Python
def is_gif(file_path: str) -> bool:
"""Check if file is a valid GIF by magic bytes."""
signature = bytes([0x47, 0x49, 0x46, 0x38, 0x37, 0x61])
with open(file_path, "rb") as f:
return f.read(6) == signature
How to validate .gif files in Node.js
Node.js
function isGIF(buffer: Buffer): boolean {
const signature = Buffer.from([0x47, 0x49, 0x46, 0x38, 0x37, 0x61]);
return buffer.subarray(0, 6).equals(signature);
}
Go
func IsGIF(data []byte) bool {
signature := []byte{0x47, 0x49, 0x46, 0x38, 0x37, 0x61}
if len(data) < 6 {
return false
}
return bytes.Equal(data[:6], signature)
}
API Endpoint
GET
/api/v1/gif
curl https://filesignature.org/api/v1/gif