Jump to content

PHP Binary Conversion


pudge1

Recommended Posts

I want to convert a .bin Binary File to a .png Image File. Here is my code:

 

<?php
$file = 'test.bin';
$fp = fopen($file, "r");
$filestream = fread($fp, filesize($file));
$filestream = base64_decode($filestream);
$stream = imagecreatefromstring($filestream);
if ($stream !== false) {
header("Content-type: image/png");
imagepng($stream);
imagedestroy($stream);
}
else {
echo "An error occured.";
}
?>

 

I don't have the kind of binary file I want to convert to test it. I am not sure if I am doing it write though in the first place. Can someone tell me if this would convert a binary file to an image by any chance?

Link to comment
https://forums.phpfreaks.com/topic/170926-php-binary-conversion/
Share on other sites

Firstly a binary file could be almost anything (not limited to an image)

the extension .bin is commonly used for CD/DVD images (not pictures but disc images)

 

the fact your using base64_decode would suggest your dealing with a MacBinary archive (which I have only seen on email on Mac OS9 (classic), However by looking at your script it would suggest you have a JPEG, PNG, GIF, WBMP, or GD2 file and are attempting to convert to png if its not one of those formats then your need to give some details

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.