Skip to content

Commit

Permalink
added possibility to use imagine new metadata api
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalkaoz committed May 22, 2014
1 parent b312ed3 commit 5e66a41
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
5 changes: 5 additions & 0 deletions DependencyInjection/LiipImagineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public function load(array $configs, ContainerBuilder $container)

$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');
$container->removeDefinition('liip_imagine.meta_data.reader');
}

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

$container->setParameter('liip_imagine.filter_sets', $config['filter_sets']);
Expand Down
22 changes: 17 additions & 5 deletions Imagine/Filter/Loader/AutoRotateFilterLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ class AutoRotateFilterLoader implements LoaderInterface
*/
public function load(ImageInterface $image, array $options = array())
{
$exifData = exif_read_data("data://image/jpeg;base64," . base64_encode($image->get('jpg')));

if (isset($exifData['Orientation'])) {
$orientation = (int) $exifData['Orientation'];
$degree = $this->calculateRotation($orientation);
if ($orientation = $this->getOrientation($image)) {
$degree = $this->calculateRotation((int)$orientation);

if ($degree !== 0) {
$image->rotate($degree);
Expand Down Expand Up @@ -55,4 +52,19 @@ private function calculateRotation($orientation)

return $degree;
}

/**
* @param ImageInterface $image
* @return int
*/
private function getOrientation(ImageInterface $image)
{
//>0.6 imagine meta data interface
if (method_exists($image, 'metadata')) {
return $image->metadata()->offsetGet('exif.Orientation');
} else {
$data = exif_read_data("data://image/jpeg;base64," . base64_encode($image->get('jpg')));
return isset($data['Orientation']) ? $data['Orientation'] : null;
}
}
}
7 changes: 6 additions & 1 deletion Resources/config/imagine.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@

<parameter key="liip_imagine.form.type.image.class">Liip\ImagineBundle\Form\Type\ImageType</parameter>

<parameter key="liip_imagine.meta_data.reader.class">Imagine\Image\Metadata\ExifMetadataReader</parameter>
</parameters>

<services>
Expand Down Expand Up @@ -98,9 +99,13 @@
<argument type="service" id="liip_imagine.cache.signer" />
</service>

<service id="liip_imagine.meta_data.reader" class="%liip_imagine.meta_data.reader.class%" />

<!-- ImagineInterface instances -->

<service id="liip_imagine" alias="liip_imagine.gd" />
<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.gd" class="%liip_imagine.gd.class%" public="false" />

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"require": {
"php": ">=5.3.2",
"imagine/Imagine": "0.5.*",
"imagine/Imagine": "~0.5",
"symfony/finder": "~2.3",
"symfony/filesystem": "~2.3",
"symfony/options-resolver": "~2.3",
Expand Down

0 comments on commit 5e66a41

Please sign in to comment.