-
Notifications
You must be signed in to change notification settings - Fork 379
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'))); | ||
|
||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?