How to decode a base64 string (gif) into image in PHP / HTML

后端 未结 5 751
别那么骄傲
别那么骄傲 2020-12-06 04:51

I have a base64 encoded string that I would like to convert into an image in PHP / HTML.

Here is what I have:

$data = \"R0lGODdhAAGAAKIAAP38+/3h3cj         


        
相关标签:
5条回答
  • 2020-12-06 05:10
    echo '<img src="data:image/gif;base64,' . $data . '" />'
    

    Should do the trick.

    0 讨论(0)
  • 2020-12-06 05:25

    Stupid question: is the mime-type correct?? is your base64 code represent a gif file????

    this is an example using a image/png, without php, just html, and it works:

    <img alt="Embedded Image" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEEAAABBCAIAAAABlV4SAAAABGdBTUEAAK/INwWK6QAAABl0RVh0
    U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAABJFSURBVHja1FoLmFTFla5zqu7tGRgRGB4J
    gkAAgSUBgyiQiIpm1UCMH6hIYkiUuJ8xhjjyIWuCGt9mjZtPTUwiefkI0fURCGh0VTRCAJOwiCyP
    CCJiEBSGcWZ6Hj3d91btOafu7ekhX1B7ZL5v23a4fW91ddV5/uc/pdRH9kL6H/iNxeviffoAJXf8
    BYAf7D90mAqSL6bzwOF+WH90e3C8UJALfqO/k/5Nlwp+L8UBTu7SMpw8whEj8NwZymi9dy89tX5o
    MvhIv0D5DSCkgveCRC8m/xFQF5VwqBLD228B59C5zEVfwiCEVKWpJrvgBbK4jhtIFoqsH+0/HD9O
    V3ZPH4AyYmRzLzGFpsA5ZZ0ZPMiUrBsBunAPqsSyAaDUMfwOZ19oNr4c3PufpsKA3wNtLMzA+jUk
    e0MasA6OG2YSv2n3HkzE03XbSMxJrsBvAceMNHUHlM2Fx4+DxFN5mJl4gpHVg+W3uvzrQXtsAJ3O
    qFkWXbMJKNE4pJuhhdx8fUirdDH7SXEldH32GVpWr+I2Za360zMGxaFKV+uVKUo1qst8QkG7CdAG
    aq4IeKFWLZxHRoJFN5h4Qmidjq2yLcpZRWNAVXgjLInCqcZAfeRawMQ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pGw2Mo/SVsa8LGi+ZoOpgi6FJPLxoxMZV7b
    nOF5sj5A8QY4ajUoJ6qYfWEApbLvVLQFrRMPY0GexWgZbZv8GJsQBSioqjIdFpqOx/Y6RlC30qUr
    6d8PGfMVKAki6YE10CCqEMWufsakFlhUKXYCFXEdiV4PO1/lQM7ip98jwBOrlUuNVMwgei/WQCJv
    KGExSuvsFNXW7SURSHKg2SRp8H6aedpcrUmiE3wgNRx+fxYEJdPFqOP0kLESgiLBmAxb1W+XEvC3
    HOQhcn58UrxFElB8bU3AQwKLfEtQLYPf55/WojhfCDmPiDESdqA6JkM6uheCS50MyttDKshYLm69
    geTtVD5BxD5ebdwMPvApl3qtKxIqPujyVexxuktKUAaHoF5cy88ANYftWGzGyWadKE3jNy4WkiDl
    fcrKcRyxBV0q6F5pZsy2TAZFyYRyHw8ciBKCSJYrwd7oRKo2zVKan3Jt4WRsxPec2vcujSOcHvM4
    bSR7W5CSrlCnBg5y48c69opUR+VhDa968uN41nm0nzz91zH9uYASL6/Jy8LLLIq9C/CWuY6h5V90
    fjjl9BjyqqWgrroaBYirt/bapOYmFcQx/UOWyOhDuV077KQJ5oJz7SyX5NbD68H8c9bOLzQmMfbv
    GwFZT8zgTjRgKd3S3IOPdTt3J/OfPkWfN8v96+n2vfcqzp6ee69Rc72joH8f99BjBY8qaNUXz4Hq
    ATxvSI7G/ibr8xZEqtec71/biS1Nseppq6rowll4H3M6jD9YphBZldCaE4GC1ypbCYitnnmGH4kL
    r9QrV8E3v+WGj1YnTc7VHQwovjiBewWhMPmblo29Z193wqcJXOgf3puoiZYQ+xCR6v4vr9phQ7ka
    +ealrAJw5fKUaYrhwHrhTIkdLZojoIRzn1MpnPvXwd0i0IhFzfezCVPGekbmLxioU4FhVdtBuhms
    e46jXdTCJZFPcBJbDef+SG9brxoO0AbN3p2mmODLTA5kRePHhXRx1hlSo3mMlA1iXwq3sAMuf4xC
    pH52GWMQlnyM+3YHX53DtOrd/2Fu/h7njdmzdP3ebg8/EM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XLk+Z04gxl80venm68E30pIWQWx1kXIa27Rz9Halcx2IIgH+X5B/fkiral
    T1XW1ISnnwZPLtXZRjz389ELawrfv1nX1iUFPoD1tUTC7FCtLRCDo7VhePbjXzD7JlHVFQeV039I
    6RmUAyERSk/fE3W0FHQJg8asCgd9QrbcH4Gq+PnluOLp8K6f5FzSfWS4dcmXdb8+7o67nUvWxBQf
    NjsGKUKrMVo1DrpT2EAMpLYgm8SCs+X2H0qyI351VsDmFLGxRtLPZG7Ud9mEJeACUrJELFxyaz12
    7xa+/JL0cJko4OBGC3r1ZW71ki0d3APza2DTWsk/UlcJFJDKLlYP/jLQqrNUcWn/M7le+2zIMTtH
    7pu0OhOiV2BInE3Id3YM2camv5Bbm4cfCLwJth3kVdXtDvfvwxHHGWlyB9dfm554oHhQz7WunN0w
    YYVO8RJCwq+UhTXYEAVf+K7fZ8+MCo2BCiEywoV72CahVvhWoZB8w4Eso0196sToxuvsl77mdm/l
    wzsUK++9J4hcNGYc9uqu71/M82cMofeY4bhlq1EhW8+1CzDfFjPqs57JdVK9lIk1jEzcfpCnf9/Q
    n5RiSZf0nj0l4UONNy3fRrBW/fC2TGWFiSMkK6LZKOtTSU0zbGLCWN2yCDmMNjMOl5pW7dxEQFy3
    H0YDpTpzdAk6NEWT6YYOkd6HSNql0TBuSFIHuYTfAI9pwpqrKilJ/+iugLNHXr35mhESgC3tC2ez
    of7qJwyrOCIXeNoN6wNoP3dWeqSu7ONwCO1igPaTPn37YFMt/zaTS1mBN9lECRTmGc+1cES5YVEw
    8riKu+4QSec9dcCm71qZK5l2ZmboCLNzY+hPodCjR5eAKhF/R7B9RE6R4eqVBJMM85Mt4IuvyDfU
    stzgooAzeHBm1KgwITuauMGTnGwQxJV9B9/cyrKPZQP/vhCNbwB20UmH9FDL7TfJabyYD1z4soaD
    UhO7wXfnM9YgH/A4JeE5myguiwW28Bi+z0/1OdMypcfQuurcXtosHT0SCE57yM1ld7Py6PWUSUk8
    6NMPqJz41WId12uXkyMbWd/85CbZmj8iFdPtTtx1R0A7Wimtde6lZOg6OfaWYwfY8Fdz+lR+FIbh
    F79YcdcPKvNNGOVYY9aX0zHO+UrxGJc3I9115z89bWpKW+hyeuw7C7Xvn9k0+JCd/HkVbn2FcZ4/
    eOgfff9Wk3JCmPiAcEvQdbqA4gngogxN0cJuuD7T1shHVqVU8oeawAef7Zux5sqg/YulEVxiIJTr
    0R/6WwSGLcQ+kxebTJAWSILNcOIkO2USDh0MQ45R3arUi6vh5w/F7+5BYSnTI+sppkwnkY/QFUfT
    i+ouNsx1IsK0b1QC9n0NgKVG4k8RwKFt/COYB/5/vP5PgAEA77fJf3rfdyAAAAAASUVORK5CYII=" />
    

    Just try it.

    Now, the same base64 code using the php exemplified above but using the proper mime-type (image/png):

    <?php
    
    echo "<img alt=Embedded Image src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEEAAABBCAIAAAABlV4SAAAABGdBTUEAAK/INwWK6QAAABl0RVh0
    U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAABJFSURBVHja1FoLmFTFla5zqu7tGRgRGB4J
    gkAAgSUBgyiQiIpm1UCMH6hIYkiUuJ8xhjjyIWuCGt9mjZtPTUwiefkI0fURCGh0VTRCAJOwiCyP
    CCJiEBSGcWZ6Hj3d91btOafu7ekhX1B7ZL5v23a4fW91ddV5/uc/pdRH9kL6H/iNxeviffoAJXf8
    BYAf7D90mAqSL6bzwOF+WH90e3C8UJALfqO/k/5Nlwp+L8UBTu7SMpw8whEj8NwZymi9dy89tX5o
    MvhIv0D5DSCkgveCRC8m/xFQF5VwqBLD228B59C5zEVfwiCEVKWpJrvgBbK4jhtIFoqsH+0/HD9O
    V3ZPH4AyYmRzLzGFpsA5ZZ0ZPMiUrBsBunAPqsSyAaDUMfwOZ19oNr4c3PufpsKA3wNtLMzA+jUk
    e0MasA6OG2YSv2n3HkzE03XbSMxJrsBvAceMNHUHlM2Fx4+DxFN5mJl4gpHVg+W3uvzrQXtsAJ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5vIt7h6HrHOvz
    W5ei+ocKo0xPh/SbjNVY7bybGecIdsgDx5M0Q7lCeOyxYQL1PXjtWD+kFku+h1NPNTZn2Pwo64mj
    0zbiRpQYxQA2apH8I/ICzkXQmRzQAcTLZXhgd8CLbpGw2Mo/SVsa8LGi+ZoOpgi6FJPLxoxMZV7b
    nOF5sj5A8QY4ajUoJ6qYfWEApbLvVLQFrRMPY0GexWgZbZv8GJsQBSioqjIdFpqOx/Y6RlC30qUr
    6d8PGfMVKAki6YE10CCqEMWufsakFlhUKXYCFXEdiV4PO1/lQM7ip98jwBOrlUuNVMwgei/WQCJv
    KGExSuvsFNXW7SURSHKg2SRp8H6aedpcrUmiE3wgNRx+fxYEJdPFqOP0kLESgiLBmAxb1W+XEvC3
    HOQhcn58UrxFElB8bU3AQwKLfEtQLYPf55/WojhfCDmPiDESdqA6JkM6uheCS50MyttDKshYLm69
    geTtVD5BxD5ebdwMPvApl3qtKxIqPujyVexxuktKUAaHoF5cy88ANYftWGzGyWadKE3jNy4WkiDl
    fcrKcRyxBV0q6F5pZsy2TAZFyYRyHw8ciBKCSJYrwd7oRKo2zVKan3Jt4WRsxPec2vcujSOcHvM4
    bSR7W5CSrlCnBg5y48c69opUR+VhDa968uN41nm0nzz91zH9uYASL6/Jy8LLLIq9C/CWuY6h5V90
    fjjl9BjyqqWgrroaBYirt/bapOYmFcQx/UOWyOhDuV077KQJ5oJz7SyX5NbD68H8c9bOLzQmMfbv
    GwFZT8zgTjRgKd3S3IOPdTt3J/OfPkWfN8v96+n2vfcqzp6ee69Rc72joH8f99BjBY8qaNUXz4Hq
    ATxvSI7G/ibr8xZEqtec71/biS1Nseppq6rowll4H3M6jD9YphBZldCaE4GC1ypbCYitnnmGH4kL
    r9QrV8E3v+WGj1YnTc7VHQwovjiBewWhMPmblo29Z193wqcJXOgf3puoiZYQ+xCR6v4vr9phQ7ka
    +ealrAJw5fKUaYrhwHrhTIkdLZojoIRzn1MpnPvXwd0i0IhFzfezCVPGekbmLx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YJx+vLvy5UZysk3B7DRwaOnvn0lRArR5ywIlN+
    p/TQ1/6d4rsEKoWK82wcrbthryy6Vfhj7oYIceZg1PDMG5v4KyOH8QLIpq+4zCx7IiTYd/xYQd1t
    qjhVAu8aMMomu/LdrZXLk+Z04gxl80venm68E30pIWQWx1kXIa27Rz9Halcx2IIgH+X5B/fkiral
    T1XW1ISnnwZPLtXZRjz389ELawrfv1nX1iUFPoD1tUTC7FCtLRCDo7VhePbjXzD7JlHVFQeV039I
    6RmUAyERSk/fE3W0FHQJg8asCgd9QrbcH4Gq+PnluOLp8K6f5FzSfWS4dcmXdb8+7o67nUvWxBQf
    NjsGKUKrMVo1DrpT2EAMpLYgm8SCs+X2H0qyI351VsDmFLGxRtLPZG7Ud9mEJeACUrJELFxyaz12
    7xa+/JL0cJko4OBGC3r1ZW71ki0d3APza2DTWsk/UlcJFJDKLlYP/jLQqrNUcWn/M7le+2zIMTtH
    7pu0OhOiV2BInE3Id3YM2camv5Bbm4cfCLwJth3kVdXtDvfvwxHHGWlyB9dfm554oHhQz7WunN0w
    YYVO8RJCwq+UhTXYEAVf+K7fZ8+MCo2BCiEywoV72CahVvhWoZB8w4Eso0196sToxuvsl77mdm/l
    wzsUK++9J4hcNGYc9uqu71/M82cMofeY4bhlq1EhW8+1CzDfFjPqs57JdVK9lIk1jEzcfpCnf9/Q
    n5RiSZf0nj0l4UONNy3fRrBW/fC2TGWFiSMkK6LZKOtTSU0zbGLCWN2yCDmMNjMOl5pW7dxEQFy3
    H0YDpTpzdAk6NEWT6YYOkd6HSNql0TBuSFIHuYTfAI9pwpqrKilJ/+iugLNHXr35mhESgC3tC2ez
    of7qJwyrOCIXeNoN6wNoP3dWeqSu7ONwCO1igPaTPn37YFMt/zaTS1mBN9lECRTmGc+1cES5YVEw
    8riKu+4QSec9dcCm71qZK5l2ZmboCLNzY+hPodCjR5eAKhF/R7B9RE6R4eqVBJMM85Mt4IuvyDfU
    stzgooAzeHBm1KgwITuauMGTnGwQxJV9B9/cyrKPZQP/vhCNbwB20UmH9FDL7TfJabyYD1z4soaD
    UhO7wXfnM9YgH/A4JeE5myguiwW28Bi+z0/1OdMypcfQuurcXtosHT0SCE57yM1ld7Py6PWUSUk8
    6NMPqJz41WId12uXkyMbWd/85CbZmj8iFdPtTtx1R0A7Wimtde6lZOg6OfaWYwfY8Fdz+lR+FIbh
    F79YcdcPKvNNGOVYY9aX0zHO+UrxGJc3I9115z89bWpKW+hyeuw7C7Xvn9k0+JCd/HkVbn2FcZ4/
    eOgfff9Wk3JCmPiAcEvQdbqA4gngogxN0cJuuD7T1shHVqVU8oeawAef7Zux5sqg/YulEVxiIJTr
    0R/6WwSGLcQ+kxebTJAWSILNcOIkO2USDh0MQ45R3arUi6vh5w/F7+5BYSnTI+sppkwnkY/QFUfT
    i+ouNsx1IsK0b1QC9n0NgKVG4k8RwKFt/COYB/5/vP5PgAEA77fJf3rfdyAAAAAASUVORK5CYII=\" />";
    
    ?>
    

    So, this is the code:

    echo "<img alt=Embedded Image src=\"data:image/png;base64,[BASE64CODE]\" />";
    

    Notice, since I am using double quotes for the echo tag, I have to tell php to ignore the ones inside the img tag. Other than that, you are good

    cheers

    PC

    0 讨论(0)
  • 2020-12-06 05:28

    Display Image using base64_encode function

    $ret = fopen($fullurl, 'r', true, $context);
    $contents = stream_get_contents($ret);
    $base64 = 'data:image/PNG;base64,' . base64_encode($contents);
    echo "<img src=$base64 />" ;
    
    0 讨论(0)
  • 2020-12-06 05:33

    In the first case you should add this before echoing the decoded image data:

    header("Content-type: image/gif");
    

    In the second case, use this instead:

    echo '<img src="data:image/gif;base64,' . $data . '" />';
    
    0 讨论(0)
  • 2020-12-06 05:34

    You have to use the header() function before echoing your data to specify the content type (gif image). Otherwise browsers will interpret it as html.

    0 讨论(0)
提交回复
热议问题