/**
  * Strip orientation from EXIF data for an image at a path.
  *
  * @param $filePath
  *
  * @return bool
  */
 public function stripOrientationFromExifData($filePath)
 {
     if (!ImageHelper::canHaveExifData($filePath)) {
         return null;
     }
     $data = new PelDataWindow(IOHelper::getFileContents($filePath));
     // Is this a valid JPEG?
     if (PelJpeg::isValid($data)) {
         $jpeg = $file = new PelJpeg();
         $jpeg->load($data);
         $exif = $jpeg->getExif();
         if ($exif) {
             $tiff = $exif->getTiff();
             $ifd0 = $tiff->getIfd();
             // Delete the Orientation entry and re-save the file
             $ifd0->offsetUnset(PelTag::ORIENTATION);
             $file->saveFile($filePath);
             return true;
         }
     }
     return false;
 }
Esempio n. 2
0
 /**
  * Strip orientation from EXIF data for an image at a path.
  *
  * @param $filePath
  *
  * @return bool
  */
 public function stripOrientationFromExifData($filePath)
 {
     if (!ImageHelper::canHaveExifData($filePath)) {
         return null;
     }
     // Quick and dirty, if possible
     if ($this->isImagick() && method_exists('Imagick', 'setImageProperty')) {
         $image = new \Imagick($filePath);
         $image->setImageOrientation(\Imagick::ORIENTATION_UNDEFINED);
         $image->writeImages($filePath, true);
         return true;
     }
     $data = new PelDataWindow(IOHelper::getFileContents($filePath));
     // Is this a valid JPEG?
     if (PelJpeg::isValid($data)) {
         $jpeg = $file = new PelJpeg();
         $jpeg->load($data);
         $exif = $jpeg->getExif();
         if ($exif) {
             $tiff = $exif->getTiff();
             $ifd0 = $tiff->getIfd();
             // Delete the Orientation entry and re-save the file
             $ifd0->offsetUnset(PelTag::ORIENTATION);
             $file->saveFile($filePath);
             return true;
         }
     }
     return false;
 }