/** * Auto rotates the image if an orientation in the exif data is found that is not 0. * * @param string $imageFile Path to the image file. * @param string $format Format of the image to save. Workaround for imagines save(). :( * @return boolean */ protected function _autoRotate($imageFile, $format) { $orientation = ImagineUtility::getImageOrientation($imageFile); $degree = 0; if ($orientation === false) { return false; } if ($orientation === 0) { return true; } switch ($orientation) { case 180: $degree = -180; break; case -90: $degree = 90; break; case 90: $degree = -90; break; } $processor = new ImageProcessor(); $image = $processor->open($imageFile); $processor->rotate($image, ['degree' => $degree]); $image->save($imageFile, ['format' => $format]); return true; }
/** * testGetImageOrientation * * @return void */ public function testGetImageOrientation() { $image = Plugin::path('Burzum/Imagine') . 'tests' . DS . 'Fixture' . DS . 'titus.jpg'; $result = ImagineUtility::getImageOrientation($image); $this->assertEquals($result, 0); $image = Plugin::path('Burzum/Imagine') . 'tests' . DS . 'Fixture' . DS . 'Portrait_6.jpg'; $result = ImagineUtility::getImageOrientation($image); $this->assertEquals($result, -90); try { ImagineUtility::getImageOrientation('does-not-exist'); $this->fail('No \\RuntimeException thrown as expected!'); } catch (\RuntimeException $e) { } }
/** * hashImageOperations * * @param array $imageSizes * @param int $hashLength * @return string */ public function hashImageOperations($imageSizes, $hashLength = 8) { return ImagineUtility::hashImageOperations($imageSizes, $hashLength = 8); }