How can I encode my image from http request with base64?

I want to encode my Image with base64:

$response = $client->request('GET', $filePath, [
                   'auth_basic' => [$user, $authKey],

if( $response->getStatusCode() == Response::HTTP_OK) {
  $imageEncoded = base64_encode($response->getContent());
  $imageFromString = imagecreatefromstring(base64_decode($imageEncoded));
  $size = getimagesizefromstring(base64_decode($imageEncoded));

I get an error message:

syntax error, unexpected ‘$imageFromString’ (T_VARIABLE)

at the line:

$size = getimagesizefromstring(base64_decode($imageEncoded));


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);