-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
leblaireau
  • 1,133
  • 4
  • 10
  • 13
  • what was the process by which you received the array in your question? – castis Jan 13 '15 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? – T0xicCode Jan 13 '15 at 16:58
  • possible duplicate of [Convert binary byte array to image in PHP](http://stackoverflow.com/questions/15222114/convert-binary-byte-array-to-image-in-php) – Jeff Lambert Jan 13 '15 at 16:59

1 Answers1

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

Le_Morri
  • 1,619
  • 14
  • 18