php - remove Exiff from UploadedFile Symfony

28

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?

642

Answer

Solution:

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

People are also looking for solutions to the problem: php - How to use array_filter in Node.js

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.