/** * {@inheritdoc} */ public function transform(File $file, $self = false) { if ($file->type() !== 'image/jpeg') { return $file; // Exif only in JPGs } $width = $file->width(); $height = $file->height(); $exif = $file->exif(); $this->setConfig('degrees', 0); // Reset degrees $options = array('dest_w' => $width, 'dest_h' => $height, 'source_w' => $width, 'source_h' => $height, 'quality' => $this->getConfig('quality'), 'overwrite' => $self, 'target' => sprintf('%s-exif-%s', $file->name(), $exif['orientation'] ?: 0)); switch ($exif['orientation']) { case 2: // Flip horizontally $options['source_x'] = $width; $options['source_w'] = -$width; break; case 3: // Rotate 180 degrees $this->setConfig('degrees', 180); break; case 4: case 5: case 7: // Flip vertically $options['source_y'] = $height; $options['source_h'] = -$height; // Also rotate -90 degrees for orientation 5 if ($exif['orientation'] == 5) { $this->setConfig('degrees', -90); } // Or rotate 90 degrees for orientation 7 if ($exif['orientation'] == 7) { $this->setConfig('degrees', 90); } break; case 6: $this->setConfig('degrees', -90); break; case 8: $this->setConfig('degrees', 90); break; default: // Correct, strip exif only break; } if ($degrees = $this->getConfig('degrees')) { $options['postCallback'] = array($this, 'rotate'); } return $this->_process($file, $options); }
/** * Test that exif() returns exif data. */ public function testExif() { $file = new File(TEMP_DIR . '/exif-data.jpg'); $this->assertEquals(array('make' => 'NIKON CORPORATION', 'model' => 'NIKON 1 J1', 'exposure' => '10/4000', 'orientation' => 1, 'fnumber' => '45/10', 'date' => '2013:06:07 11:32:22', 'iso' => 100, 'focal' => '100/10'), $file->exif()); $file = new File(TEMP_DIR . '/magic-mime-verify.js'); $this->assertEquals(array('make' => '', 'model' => '', 'exposure' => '', 'orientation' => '', 'fnumber' => '', 'date' => '', 'iso' => '', 'focal' => ''), $file->exif()); }