/**
  * Perform the crop.
  */
 public function performCrop()
 {
     // Calculate the missing width/height for the asset - ensure aspect ratio is maintained
     $dimensions = ImageHelper::calculateMissingDimension($this->width, $this->height, $this->image->getWidth(), $this->image->getHeight());
     $this->image = $this->image->scaleAndCrop($dimensions[0], $dimensions[1]);
 }
 /**
  * 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;
 }
Example #3
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;
 }