Skip to content

Instantly share code, notes, and snippets.

@feketegy
Created September 12, 2014 14:54
Show Gist options
  • Save feketegy/0cb1488f0320d1fa81d0 to your computer and use it in GitHub Desktop.
Save feketegy/0cb1488f0320d1fa81d0 to your computer and use it in GitHub Desktop.
$png = [
'format' => 'H32',
'marker' => '89504e470d0a1a0a0000000d49484452'
];
$bytes_to_read = strlen( $png['marker'] ) / 2;
$fp = fopen('your-filename.png', 'r');
$data = fread($fp, $bytes_to_read);
fclose($fp);
$x = unpack( $png['format'], $data);
$is_png = ( $x[1] == strtolower( $png['marker'] ) ) ? true : false;
var_dump( $is_png );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment