Search code examples
phpbase64httpclientencode

How can I encode/decode to base64?


I want to encode/decode my Image with base64:

  $imageEncoded = base64_encode($image);
  $imageDecoded = imagecreatefromstring(base64_decode($imageEncoded));

But it is not correctly decoded


Solution

  • You don't have to use imagecreatefromstring in your code. You can encode/decode with php base64 functions.

    $imageEncoded = base64_encode($your_image);
    $imageDecoded = base64_decode($imageEncoded);