如何删除此函数中的exif数据?

Its my function, i dont know how delete exif data from pictures wich are uploded. Thanks )

$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'));
        }

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.

This piece of code should delete all EXIF information in JPEG

$img = new Imagick($uploadfile);
$img->stripImage();
$img->writeImage($uploadfile);