Skip to content
This repository was archived by the owner on Nov 16, 2022. It is now read-only.

Commit 86c3fbd

Browse files
authored
Merge pull request #218 from chronon/add-orientate
Add orientate method
2 parents e90bb1a + e1d12ee commit 86c3fbd

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

docs/configuration.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ Additional thumbnail generation types are available using the `crop` and `fit` o
4949
'portrait' => [
5050
'w' => 150,
5151
'h' => 300,
52-
'crop' => true
52+
'crop' => true,
53+
'orientate' => true
5354
]
5455
```
5556

5657
#### Fit
57-
> Combine cropping and resizing to format image in a smart way. The method will find the best fitting aspect ratio of
58+
> Combine cropping and resizing to format image in a smart way. The method will find the best fitting aspect ratio of
5859
> your given width and height on the current image automatically, cut it out and resize it to the given dimension.
5960
See [Intervention Fit method](http://image.intervention.io/api/fit)
6061

@@ -63,6 +64,10 @@ See [Intervention Fit method](http://image.intervention.io/api/fit)
6364
By default, will be the centre of the image.
6465
See [Intervention Crop method](http://image.intervention.io/api/crop)
6566

67+
#### Orientate
68+
> Reads the EXIF image profile setting 'Orientation' and performs a rotation on the image to display the image correctly.
69+
See [Intervention Orientate method](http://image.intervention.io/api/orientate) for PHP installation requirements.
70+
6671
## Template
6772
In order to upload a file to your application you will need to add the form fields to your view.
6873
```php
@@ -105,7 +110,7 @@ If you want to replace the creation of thumbnails you can specify your own class
105110
EG, `'transformClass' => App\Lib\Proffer\WatermarkThumbnail::class`.
106111

107112
## Associating many uploads to a parent
108-
If you need to associate many uploads to a single parent entity, the same process as above applies, but you should attach
113+
If you need to associate many uploads to a single parent entity, the same process as above applies, but you should attach
109114
and configure the behaviour on the association.
110115

111116
Let's look at an example.
@@ -128,8 +133,8 @@ $this->addBehavior('Proffer.Proffer', [
128133
Now, when you save a post, with associated Uploads data, each upload will be converted to an entity, and saved.
129134

130135
### Uploading multiple files
131-
So now you've configured the behaviour and created the table associations, you'll need to get the request data. If you're
132-
using HTML5, then you can use the file input, with the `multiple` flag, to allow for multiple file upload fields. Older
136+
So now you've configured the behaviour and created the table associations, you'll need to get the request data. If you're
137+
using HTML5, then you can use the file input, with the `multiple` flag, to allow for multiple file upload fields. Older
133138
browsers will see this as a single file upload field instead of multiple.
134139

135140
:warning: Note that the field name is an array!

src/Lib/ImageTransform.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ public function makeThumbnail($prefix, array $config)
8888

8989
$image = $this->ImageManager->make($this->Path->fullPath());
9090

91+
if (!empty($config['orientate'])) {
92+
$image = $this->orientate($image);
93+
}
94+
9195
if (!empty($config['crop'])) {
9296
$image = $this->thumbnailCrop($image, $width, $height);
9397
} elseif (!empty($config['fit'])) {
@@ -98,7 +102,7 @@ public function makeThumbnail($prefix, array $config)
98102
$image = $this->thumbnailResize($image, $width, $height);
99103
}
100104

101-
unset($config['crop'], $config['w'], $config['h'], $config['custom'], $config['params']);
105+
unset($config['crop'], $config['w'], $config['h'], $config['custom'], $config['params'], $config['orientate']);
102106

103107
$image->save($this->Path->fullPath($prefix), $config['jpeg_quality']);
104108

@@ -168,4 +172,17 @@ protected function thumbnailCustom(Image $image, $custom, $params)
168172
{
169173
return call_user_func_array([$image, $custom], $params);
170174
}
175+
176+
/**
177+
* EXIF orientate the current image
178+
*
179+
* @see http://image.intervention.io/api/orientate
180+
*
181+
* @param \Intervention\Image\Image $image Image instance
182+
* @return \Intervention\Image\Image
183+
*/
184+
protected function orientate(Image $image)
185+
{
186+
return $image->orientate();
187+
}
171188
}

tests/TestCase/Model/Behavior/ProfferBehaviorTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class ProfferBehaviorTest extends PHPUnit_Framework_TestCase
3535
'thumbnailSizes' => [
3636
'square' => ['w' => 200, 'h' => 200, 'crop' => true],
3737
'portrait' => ['w' => 100, 'h' => 300],
38+
'large' => ['w' => 1200, 'h' => 900, 'orientate' => true],
3839
]
3940
]
4041
];
@@ -99,7 +100,8 @@ protected function _getProfferPathMock(Table $table, Entity $entity)
99100
->with($this->logicalOr(
100101
$this->equalTo(null),
101102
$this->equalTo('square'),
102-
$this->equalTo('portrait')
103+
$this->equalTo('portrait'),
104+
$this->equalTo('large')
103105
))
104106
->will($this->returnCallback(
105107
function ($param) use ($table, $entity) {
@@ -545,6 +547,7 @@ public function testEventsForBeforeSave()
545547
$path->getFolder() . 'image_640x480.jpg',
546548
$path->getFolder() . 'square_image_640x480.jpg',
547549
$path->getFolder() . 'portrait_image_640x480.jpg',
550+
$path->getFolder() . 'large_image_640x480.jpg',
548551
];
549552
$eventAfterCreateImage = new Event('Proffer.afterCreateImage', $entity, ['path' => $path, 'images' => $images]);
550553

0 commit comments

Comments
 (0)