-1

I have an array, below is part of it (it is over 3000 items) and I need to convert the byte data to an image (jpg) any ideas how I do this?

Thanks.

[0] => 255
    [1] => 216
    [2] => 255
    [3] => 224
    [4] => 0
    [5] => 16
    [6] => 74
    [7] => 70
    [8] => 73
    [9] => 70
    [10] => 0
    [11] => 1
    [12] => 1
    [13] => 1
    [14] => 0
    [15] => 96
    [16] => 0
    [17] => 96
    [18] => 0
    [19] => 0
    [20] => 255
3
  • what was the process by which you received the array in your question? Commented Jan 13, 2015 at 16:58
  • Is the array just the numerical representation of the image data, i.e. if I encounter 216, does it mean that the byte should have the value 216? Commented Jan 13, 2015 at 16:58
  • possible duplicate of Convert binary byte array to image in PHP Commented Jan 13, 2015 at 16:59

1 Answer 1

2

This should be working

$fp = fopen("image.jpg", "wb");

$len = count($array);

for ($i = 0; $i < $len; $i++) {
    $data = pack("C*",$array[$i]);
    fwrite($fp, $data);
}
fclose($fp);

adopted from here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.