Jump to content

Using base64_decode to display a GIF image from an Array


mmc215

Recommended Posts

Hey folks, I am using a PHP product to produce shipping labels directly from a major carrier. The php script returns an array of info with the image data sent in Base64 format.

 

I'm told that I can display this as an image (GIF) in the broswer with this format but I'm pretty much lost (don't laugh, I'm only an html/css simpleton):

 

<img src="data:image/gif;base64,iVBORw0KGgoAAAANS..." />

 

Here's the resulting data I need to turn into a printable GIF image:

 

Array
(
  [charges] => 6.89
  [trk_main] => 1Z5977460394839629
  [pkgs] => Array
    (
      [0] => Array
        (
        [pkg_trk_num] => 1Z5977460394839629
        [label_fmt] => ZPL
        [label_img] => Cl5YQV5MUk5eTU5ZXk1GTixOXkxIMTUsMTBPSV5QVzg...

 

 

Any help would be so awesomely appreciated!

mmc

 

 

Link to comment
Share on other sites

Not tested, but maybe something like this:

 

display.php

<?php
header('Content-Type: image/gif'); 
echo base64_decode($array['pkgs'][0]['label_img']);
?>

 

Then wherever you want to display it:

<img src="display.php" />

Would need to see more code or have an explanation of how you retrieve this data.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.