0

I don't know how delete exif data from uploaded pictures. Here is my function:

$uploadedFiles = $request->getUploadedFiles();

if ($uploadedFiles && $id) {
    $usersPath = '/collections/' . date('Y/m') . '/' . $id .'/';
    $uploadFolder = realpath(BASE_PATH . '/uploads');
    $uploadFolder .= $usersPath;
    $newName = md5(time() . serialize($uploadedFiles));

    $fileExtension = strtolower($uploadedFiles[0]->getExtension());
    $sourceImgPath = $uploadFolder .$newName .'.' .$fileExtension;

    if (!file_exists($uploadFolder)) {
        mkdir($uploadFolder, 0777, true );
    }

    if(in_array($fileExtension, array('jpg', 'jpeg', 'png', 'gif'))){

        if ($uploadedFiles[0]->moveTo($sourceImgPath)) {
            $info = pathinfo($sourceImgPath);

            if ($info) {
                $file_path = $usersPath . $info['filename'] . '.' . $fileExtension;
                (new \Rapid\Storage\CollectionsStorage())->editImage($id, $file_path);
            } else {
                $session->set('msg_error', $this->translate->_('There was an unexpected error with uploading the file'));
            }
        }
    }
} else {
    $session->set('msg_error', $this->translate->_('Invalid file type'));
}
reformed
  • 4,505
  • 11
  • 62
  • 88

2 Answers2

1

This piece of code should delete all EXIF information in JPEG

$img = new Imagick($uploadfile);
$img->stripImage();
$img->writeImage($uploadfile);
buffy.cz
  • 66
  • 5
0

It depends on the graphics libraries you have access to.

  • If you have access to imagick, you can use stripImage().
  • If you have only access to gd, you need to create a new image from the upload and save that instead, see for example PHP remove exif data from images for a jpg image.
Community
  • 1
  • 1
jeroen
  • 91,079
  • 21
  • 114
  • 132