Canon digital camera RAW file
image/x-canon-cr2
Magic Bytes
Offset: 0
4D 4D 00 2A
The Canon Digital Camera RAW (CR2) format is a proprietary image file type developed by Canon Inc. based on the TIFF specification. It is primarily used by professional photographers to capture unprocessed sensor data for extensive post-processing and digital archiving. While generally considered a safe format for media storage, it is now largely classified as a legacy standard having been superseded by the newer CR3 format in modern camera models.
Validation Code
How to validate .cr2 files in Python
Python
def is_cr2(file_path: str) -> bool:
"""Check if file is a valid CR2 by magic bytes."""
signature = bytes([0x4D, 0x4D, 0x00, 0x2A])
with open(file_path, "rb") as f:
return f.read(4) == signature
How to validate .cr2 files in Node.js
Node.js
function isCR2(buffer: Buffer): boolean {
const signature = Buffer.from([0x4D, 0x4D, 0x00, 0x2A]);
return buffer.subarray(0, 4).equals(signature);
}
Go
func IsCR2(data []byte) bool {
signature := []byte{0x4D, 0x4D, 0x00, 0x2A}
if len(data) < 4 {
return false
}
return bytes.Equal(data[:4], signature)
}
API Endpoint
GET
/api/v1/cr2
curl https://filesignature.org/api/v1/cr2