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

added possibility to use imagine new metadata api #413

Merged
merged 2 commits into from
May 22, 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
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