-4

I want to encode/decode my Image with base64:

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

But it is not correctly decoded

peace_love
  • 6,229
  • 11
  • 69
  • 157
  • [PHP parse/syntax errors; and how to solve them](https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – Definitely not Rafal Apr 01 '21 at 12:33
  • Provide the full error message (including the part which states at which line the error occurs, when you do that, make sure to let us know which line this refers to.) – Definitely not Rafal Apr 01 '21 at 12:40
  • And you copied the code and is therefor **exactly** like this as shown in your question and does not lack a `;` in the line above `$imageFromString = imagecreatefromstring(base64_decode($imageEncoded));`? – Definitely not Rafal Apr 01 '21 at 12:43
  • 1
    The mentioned duplicate is not just about quotes. – CBroe Apr 01 '21 at 12:46
  • 1
    And the code as currently shown above, does not throw any _parse_ errors at all, as https://3v4l.org/pMv4E proves. – CBroe Apr 01 '21 at 12:47
  • 1
    Then why are you showing us this code, and say it gave you that specific error - when it actually doesn’t? – CBroe Apr 01 '21 at 12:52
  • 1
    I feel like you are not being completely honest. Suddenly the error changes? And you changed nothing? For same inputs it should generate same outputs (including same errors) unless youre programming a random number generator. Downvoting, because this is a different question. – Definitely not Rafal Apr 01 '21 at 12:52

1 Answers1

1

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);
Eagleclaw
  • 369
  • 1
  • 13
  • But how can I get now the image size? – peace_love Apr 01 '21 at 12:35
  • How can I create the resampled image without getimagesizefromstring? – peace_love Apr 01 '21 at 12:37
  • `$imageDecoded` should be an image already. All the image info, including image size should be already encoded in base64_encode and can be restored with base64_decode. Can you please try to use `$imageDecoded` as your image at where you want to display. – Eagleclaw Apr 01 '21 at 12:40