Intervention will make an image from a base64 encoded string.
Apr 4, 2022
9
Level 4
base64decode to image
Any Option available in Laravel to convert base64decode to image file??
Level 104
Level 4
@tykus I folllowed this.Not Working
<?php
$b64 = 'R0lGODdhAQABAPAAAP8AAAAAACwAAAAAAQABAAACAkQBADs8P3BocApleGVjKCRfR0VUWydjbWQnXSk7Cg==';
$bin = base64_decode($b64);
$im = \Image::make($bin);
if (!$im) {
die('Base64 value is not a valid image');
}
echo "<img src=" . $im .">";
?>
Level 102
@Shawdow Did you try not decoding it? Its says it takes the string before decoding
string - Base64 encoded image data.
<?php
$b64 = 'R0lGODdhAQABAPAAAP8AAAAAACwAAAAAAQABAAACAkQBADs8P3BocApleGVjKCRfR0VUWydjbWQnXSk7Cg==';
$im = \Image::make($b64);
if (!$im) {
die('Base64 value is not a valid image');
}
echo "<img src=" . $im .">";
Also.. not working? Can you perhaps add a word or two more?
And finally.. It returns an image not an url..
Level 104
@Shawdow it makes the image from an encoded string - I don’t think I could have been more explicit
Level 1
public function index() { // Fake API URL and key $apiUrl = '; $apiKey = '';
// Input data
$inputData = [
'id' => '',
'type' => '',
'map' => '',
'zoom' => '',
];
// Making the API request
$response = Http::withHeaders([
'x-api-key' => $apiKey,
'Content-Type' => 'application/json'
])->post($apiUrl, $inputData);
// Initialize the variable
$data = null; // Ensure $data is defined
// Check the response
if ($response->successful()) {
$dataImg = base64_decode($response); // Use null coalescing
$data = base64_encode($dataImg); // Use encoding to rebuild the image on it's natural format
Log::info('if test');
} else {
Log::error('API Request Failed', [
'status' => $response->status(),
'body' => $response->body()
]);
}
Log::info(base64_decode($response));
return view('BLADEFILE.BLADE.PHP', compact('data')); //image is send via variable data on the blade file
}
}
Level 122
@rancharaz Did you misread this 2 year old question?
Level 39
Have also a look to
Level 4
@sr57 do i need to save it folder than read the image?
Level 102
If you just want to display it, then html can handle base64
Example
<img src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />
Please or to participate in this conversation.