Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix auto rotate #476

Merged
merged 1 commit into from
Aug 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not related to this PR .. but I guess the else isn't needed if we always return in the if

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The if is for old version of imagine bundle. but no idea if the else part is working as it should.

$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