Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Ruby isJPEG? method
# @param [Object] block A 512 byte block to check if it contains a jpeg header in first 4 bytes
def isJPEG?(block)
# Encodings are diff between reading an image file and strings so block[0] == 0xFF wont work
jpeg_header_part = ['FFD8FF'].pack('H*')
return block[0,3] == jpeg_header_part && (block[3] == 0xe0.chr || block[3] == 0x0e1.chr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.