Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.