xxteknolustxx Posted June 30, 2009 Share Posted June 30, 2009 hi guys first post, cool forums, I am trying to read the binary behind a bitmap image and I dont know the best way about going about it, I am trying to read to examine the contents of the bitmap, cause the binary is going to be stored in a db, and then exported back in bitmap format any suggestions would greatly help, thanks in advance <?php $filename = "file"; $handle = fopen($filename, "rb"); set_magic_quotes_runtime(true); $contents = fread($handle, 128); fclose($handle); print_r(unpack("A*",$contents)); ?> outputs: Array ( [1] => BM�\0\0\0\0\06\0\0\0(\0\0\0,\0\0,\0\0\0\0\0\0\0\0�\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0�d*�]$�`\'�d*�]$�`\'�d*�]$�`\'�d*�]$�`\'�d*�]$�`\'�d*�]$�`\'�d*�]$�`\'�d*�]$�`\'�d ) first 4 bytes are supposed to the size of an image thats pretty much all i know, but once i get the output correct, I can move file pointer around to read and write different thing Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted June 30, 2009 Share Posted June 30, 2009 What information do you need from it before you insert it into your database? This should be all it takes. $fh=fopen($file, "r"); $data=addslashes($fh, filesize($file))); Quote Link to comment Share on other sites More sharing options...
xxteknolustxx Posted June 30, 2009 Author Share Posted June 30, 2009 well the bmp everything is clustered into 2byte chunks I need all the binary data from the bitmap, because the data differs based on what chunk is being examined I feel as if my output is not correct at all Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.