Skip to content

Instantly share code, notes, and snippets.

@edutrul
Last active February 15, 2023 18:37
Show Gist options
  • Save edutrul/6f30626581318fccee59de9acb14b857 to your computer and use it in GitHub Desktop.
Save edutrul/6f30626581318fccee59de9acb14b857 to your computer and use it in GitHub Desktop.
PHP Convert byte array to php image and display to browser
<?php
// https://example.com/api/v1/file?id=8972893948981
// Displays the following json object:
// {"asset":{"file":{"data":[-119,80,78,71,13,10,26,10,0,0,0,13,73,,,,, etc
// Here's the php cone snippet to display to image in the browser.
$result = json_decode(file_get_contents($full_url));
$raw_png = implode(array_map('chr', $result->asset->file->data));
header('Content-Type: image/png');
print $raw_png;
die ($raw_png);
// Further documentation in https://stackoverflow.com/questions/23210354/create-image-from-numerical-array-of-data-in-php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment