1

I have form that use to upload picture. I can't save this picture on my server, But I send it to another service ( external)

I have to encode base 64

my code is:

$base_img = base64_encode(file_get_contents($data["image"]));

where $data['image'] is UploadedFile

How can Remove all Exiff from $data['image'] before encode?

monkeyUser
  • 4,301
  • 7
  • 46
  • 95

1 Answers1

0

Recently I needed exactly that and I achieved it with passing $uploadedFile->getRealPath() to the Imagick. Complete function:

/**
 * @param UploadedFile $uploadedFile
 * @throws \ImagickException
 */
public function stripMeta(UploadedFile $uploadedFile): void
{
    $img = new Imagick($uploadedFile->getRealPath());
    $profiles = $img->getImageProfiles("icc", true);
    $img->stripImage();
    if(!empty($profiles)) {
        $img->profileImage("icc", $profiles['icc']);
    }
    $img->writeImage($uploadedFile->getRealPath());
}

I took saving icc profile idea from comments here: https://www.php.net/manual/en/imagick.stripimage.php

Paul Mark
  • 161
  • 3
  • 17