Skip to content

Commit

Permalink
Merge pull request #413 from digitalkaoz/metadata_reader
Browse files Browse the repository at this point in the history
added possibility to use imagine new metadata api
  • Loading branch information
makasim committed May 22, 2014
2 parents b312ed3 + 0e35347 commit 92e6495
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%" public="false" />

<!-- 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,<0.7",
"symfony/finder": "~2.3",
"symfony/filesystem": "~2.3",
"symfony/options-resolver": "~2.3",
Expand Down

0 comments on commit 92e6495

Please sign in to comment.