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 an "auto_rotate" filter based on exif data #254

Merged
merged 2 commits into from
Jan 29, 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
58 changes: 58 additions & 0 deletions Imagine/Filter/Loader/AutoRotateFilterLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Liip\ImagineBundle\Imagine\Filter\Loader;

use Imagine\Image\ImageInterface;

/**
* AutoRotateFilterLoader - rotates an Image based on its EXIF Data
*
* @author Robert Schönthal <robert.schoenthal@gmail.com>
*/
class AutoRotateFilterLoader implements LoaderInterface
{
/**
* {@inheritDoc}
*/
public function load(ImageInterface $image, array $options = array())
{
$exifData = exif_read_data("data://image/jpeg;base64," . base64_encode($image->get('jpg')));
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't this logic available in Imagine?

/cc @avalanche123

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope, not yet, there are several open PRs for metadata support, but non of them is merged

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm doesn't seem like @avalanche123 is stil active .. @romainneutron ?

Choose a reason for hiding this comment

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

There's a WIP here php-imagine/Imagine#266

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah just found this ticket too .. so are you hopeful this will get merged soon?

Choose a reason for hiding this comment

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

I'm highly open for such feature, we just need to find a nice way to introduce metadata.
I'm a bit busy currently, but I hope we could find some time to merge this in the next weeks. This is the messing feature of Imagine 0.6

Copy link
Contributor

Choose a reason for hiding this comment

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

@digitalkaoz can you maybe see if you can push this imagine PR forward?


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

if ($degree !== 0) {
$image->rotate($degree);
}
}

return $image;
}

/**
* calculates to rotation degree from the EXIF Orientation
*
* @param int $orientation
* @return int
*/
private function calculateRotation($orientation)
{
switch ($orientation) {
case 8:
$degree = -90;
break;
case 3:
$degree = 180;
break;
case 6:
$degree = 90;
break;
default:
$degree = 0;
break;
}

return $degree;
}
}
5 changes: 5 additions & 0 deletions Resources/config/imagine.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<parameter key="liip_imagine.filter.loader.strip.class">Liip\ImagineBundle\Imagine\Filter\Loader\StripFilterLoader</parameter>
<parameter key="liip_imagine.filter.loader.background.class">Liip\ImagineBundle\Imagine\Filter\Loader\BackgroundFilterLoader</parameter>
<parameter key="liip_imagine.filter.loader.upscale.class">Liip\ImagineBundle\Imagine\Filter\Loader\UpscaleFilterLoader</parameter>
<parameter key="liip_imagine.filter.loader.auto_rotate.class">Liip\ImagineBundle\Imagine\Filter\Loader\AutoRotateFilterLoader</parameter>

<!-- Data loaders' classes -->

Expand Down Expand Up @@ -165,6 +166,10 @@
<tag name="liip_imagine.filter.loader" loader="upscale" />
</service>

<service id="liip_imagine.filter.loader.auto_rotate" class="%liip_imagine.filter.loader.auto_rotate.class%">
<tag name="liip_imagine.filter.loader" loader="auto_rotate" />
</service>

<!-- Data loaders -->

<service id="liip_imagine.data.loader.filesystem" class="%liip_imagine.data.loader.filesystem.class%">
Expand Down
12 changes: 12 additions & 0 deletions Resources/doc/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ liip_image:
position: center
```

### The `auto_rotate` filter

The auto_rotate filter rotates the image based on its EXIF data. **(this filter should be called as early as possible)**
Configuration looks like this:

``` yaml
liip_imagine:
filter_sets:
my_thumb:
filters:
auto_rotate: ~
```
## Load your Custom Filters

The ImagineBundle allows you to load your own custom filter classes. The only
Expand Down