Skip to content

Commit

Permalink
Merge pull request #476 from scuben/fix-auto-rotate
Browse files Browse the repository at this point in the history
fix auto rotate
  • Loading branch information
makasim committed Aug 19, 2014
2 parents a85ef19 + b3bfa6f commit b577c2d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
10 changes: 6 additions & 4 deletions DependencyInjection/LiipImagineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

class LiipImagineExtension extends Extension
Expand Down Expand Up @@ -62,13 +63,14 @@ public function load(array $configs, ContainerBuilder $container)
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('imagine.xml');

$container->setAlias('liip_imagine', new Alias('liip_imagine.'.$config['driver']));

if (!class_exists('Imagine\Image\Metadata\MetadataReaderInterface')) {
$container->getDefinition('liip_imagine.'.$config['driver'])->removeMethodCall('setMetadataReader');
if (interface_exists('Imagine\Image\Metadata\MetadataReaderInterface')) {
$container->getDefinition('liip_imagine.'.$config['driver'])->addMethodCall('setMetadataReader', array(new Reference('liip_imagine.meta_data.reader')));
} else {
$container->removeDefinition('liip_imagine.meta_data.reader');
}

$container->setAlias('liip_imagine', new Alias('liip_imagine.'.$config['driver']));

$container->setParameter('liip_imagine.cache.resolver.default', $config['cache']);

$container->setParameter('liip_imagine.filter_sets', $config['filter_sets']);
Expand Down
16 changes: 15 additions & 1 deletion Imagine/Filter/Loader/AutoRotateFilterLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
*/
class AutoRotateFilterLoader implements LoaderInterface
{

protected $orientationKeys = array(
'exif.Orientation',
'ifd0.Orientation'
);

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -61,7 +67,15 @@ private function getOrientation(ImageInterface $image)
{
//>0.6 imagine meta data interface
if (method_exists($image, 'metadata')) {
return $image->metadata()->offsetGet('exif.Orientation');
foreach ($this->orientationKeys as $orientationKey) {
$orientation = $image->metadata()->offsetGet($orientationKey);

if ($orientation) {
return $orientation;
}
}

return null;
} else {
$data = exif_read_data("data://image/jpeg;base64," . base64_encode($image->get('jpg')));
return isset($data['Orientation']) ? $data['Orientation'] : null;
Expand Down
4 changes: 1 addition & 3 deletions Resources/config/imagine.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@

<!-- ImagineInterface instances -->

<service id="liip_imagine" alias="liip_imagine.gd">
<call method="setMetadataReader"><argument type="service" id="liip_imagine.meta_data.reader" /></call>
</service>
<service id="liip_imagine" alias="liip_imagine.gd" />

<service id="liip_imagine.gd" class="%liip_imagine.gd.class%" public="false" />

Expand Down

0 comments on commit b577c2d

Please sign in to comment.