Last active
February 15, 2023 18:37
-
-
Save edutrul/6f30626581318fccee59de9acb14b857 to your computer and use it in GitHub Desktop.
PHP Convert byte array to php image and display to browser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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