convert binary data to image using php -
this question has answer here:
- coverting hex image in php? 2 answers
i have binary image data saved in old database, saved old developer, want display image using php, can not.
i have tried imagecreatefromstring returns false.
binary example data: http://freezinfo.com/gg.php
given string displayed text (extactly sequence), it's lineup of hexadecimal numbers.
in jpeg, magic numbers of such file ff d8 first 2 bytes , ff d9 last 2 bytes (compare how identify contents of byte[] jpeg?).
these hexadecimal (hex in short) numbers can found @ beginning , end of sequence well:
ff00d800ff00 ... 1f00ff00d9000 ## ## ## ## looking these magic numbers reveals hex values append 00 always. shows @ end single 0 found.
so 4 characters form 1 value. hex-encoded looks 16 bit values value never goes on 8 bit range (0-255), therefore there 00 visible.
with information alone 1 can try turn binary string php's imagecreatefromstring can deal with:
$string = implode('', // map array of binary strings binary string array_map('chr', // map ord integer value character unpack('v*', // unsigned short (always 16 bit, little endian byte order) pack("h*", $data) // hex binary (high nibble first) ))); using such string in
$result = imagecreatefromstring($string); imagejpeg($result, 'test.jpg'); reveals following php error notice:
imagecreatefromstring(): gd-jpeg, libjpeg: recoverable error: corrupt jpeg data: bad huffman code
and following image:

this looks desperately broken. facing additional encoding problem here. last nul byte suggests more has been done , there must reason why data has been stored 16 bit hex values instead of binary data (blob) databases have support that.
but don't waste time, because of flaw in software , configuration used in past, might data-loss can restore backups.
Comments
Post a Comment