node.js - Magic number for google Image Format -
i developing (node.js) own small procedure check file (image) types. far good, until tried add validation google webp format.
as guide magic number have used file-type library. in source code list magic number webp (line 45):
0x57, 0x45, 0x42, 0x50
in library using first 2 bytes. used 0x57 , 0x45 reference.
after implementation, needed proper image sample. dug this out. official google library sample. image downloaded there, has different signature. getting:
0x52 , 0x49 tried find magic number webp, without success. able find wiki. not provide magic number.
now hope understand dilemma. information should use? 1 file-type library, or take information downloaded image sample google?
to summarise question, should use:
0x52 , 0x49 (image signature, downloaded google)
or
0x57 , 0x45 (sample image-type library)
or
something entirely else?
according google's webp container specification, webp file header both lossy , lossless formats consists of 12 bytes:
- the 32-bit riff tag, consisting of 4 ascii letters 'r', 'i', 'f', 'f', i.e. 0x52, 0x49, 0x46, 0x46.
- the file size minus 8, specified 32-bit unsigned integer in little-endian byte order.
- the 32-bit webp tag, consisting of 4 ascii letters 'w', 'e', 'b', 'p', i.e. 0x57, 0x45, 0x42, 0x50.
so "image signature, downloaded google" first byte pair of riff tag, while "sample image-type library" first byte pair of webp tag. webp images stored in files or transmitted on internet comprise riff header, should check letters 'r', 'i', i.e. 0x52, 0x49.
note, however, checking first 2 bytes rather inaccurate. safe signature check test first 4 bytes 'riff', skip 4 length bytes, check 'webp'.
Comments
Post a Comment