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

Commit

Permalink
Merge pull request #227 from davidyell/develop
Browse files Browse the repository at this point in the history
Merge for release
  • Loading branch information
davidyell committed Apr 3, 2017
2 parents 7796dcc + c55f7ef commit a3f13e0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
15 changes: 10 additions & 5 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ Additional thumbnail generation types are available using the `crop` and `fit` o
'portrait' => [
'w' => 150,
'h' => 300,
'crop' => true
'crop' => true,
'orientate' => true
]
```

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

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

#### Orientate
> Reads the EXIF image profile setting 'Orientation' and performs a rotation on the image to display the image correctly.
See [Intervention Orientate method](http://image.intervention.io/api/orientate) for PHP installation requirements.

## Template
In order to upload a file to your application you will need to add the form fields to your view.
```php
Expand Down Expand Up @@ -105,7 +110,7 @@ If you want to replace the creation of thumbnails you can specify your own class
EG, `'transformClass' => App\Lib\Proffer\WatermarkThumbnail::class`.

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

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

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

:warning: Note that the field name is an array!
Expand Down
19 changes: 18 additions & 1 deletion src/Lib/ImageTransform.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public function makeThumbnail($prefix, array $config)

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

if (!empty($config['orientate'])) {
$image = $this->orientate($image);
}

if (!empty($config['crop'])) {
$image = $this->thumbnailCrop($image, $width, $height);
} elseif (!empty($config['fit'])) {
Expand All @@ -98,7 +102,7 @@ public function makeThumbnail($prefix, array $config)
$image = $this->thumbnailResize($image, $width, $height);
}

unset($config['crop'], $config['w'], $config['h'], $config['custom'], $config['params']);
unset($config['crop'], $config['w'], $config['h'], $config['custom'], $config['params'], $config['orientate']);

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

Expand Down Expand Up @@ -168,4 +172,17 @@ protected function thumbnailCustom(Image $image, $custom, $params)
{
return call_user_func_array([$image, $custom], $params);
}

/**
* EXIF orientate the current image
*
* @see http://image.intervention.io/api/orientate
*
* @param \Intervention\Image\Image $image Image instance
* @return \Intervention\Image\Image
*/
protected function orientate(Image $image)
{
return $image->orientate();
}
}
10 changes: 2 additions & 8 deletions src/Lib/ProfferPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,11 @@ public function generateSeed($seed = null)
*/
public function fullPath($prefix = null)
{
$table = $this->getTable();
$table = (!empty($table)) ? $table . DS : null;

$seed = $this->getSeed();
$seed = (!empty($seed)) ? $seed . DS : null;

if ($prefix) {
return $this->getRoot() . DS . $table . $this->getField() . DS . $this->getSeed() . DS . $prefix . '_' . $this->getFilename();
return $this->getFolder() . $prefix . '_' . $this->getFilename();
}

return $this->getRoot() . DS . $table . $this->getField() . DS . $seed . $this->getFilename();
return $this->getFolder() . $this->getFilename();
}

/**
Expand Down
5 changes: 4 additions & 1 deletion tests/TestCase/Model/Behavior/ProfferBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ProfferBehaviorTest extends PHPUnit_Framework_TestCase
'thumbnailSizes' => [
'square' => ['w' => 200, 'h' => 200, 'crop' => true],
'portrait' => ['w' => 100, 'h' => 300],
'large' => ['w' => 1200, 'h' => 900, 'orientate' => true],
]
]
];
Expand Down Expand Up @@ -99,7 +100,8 @@ protected function _getProfferPathMock(Table $table, Entity $entity)
->with($this->logicalOr(
$this->equalTo(null),
$this->equalTo('square'),
$this->equalTo('portrait')
$this->equalTo('portrait'),
$this->equalTo('large')
))
->will($this->returnCallback(
function ($param) use ($table, $entity) {
Expand Down Expand Up @@ -545,6 +547,7 @@ public function testEventsForBeforeSave()
$path->getFolder() . 'image_640x480.jpg',
$path->getFolder() . 'square_image_640x480.jpg',
$path->getFolder() . 'portrait_image_640x480.jpg',
$path->getFolder() . 'large_image_640x480.jpg',
];
$eventAfterCreateImage = new Event('Proffer.afterCreateImage', $entity, ['path' => $path, 'images' => $images]);

Expand Down

0 comments on commit a3f13e0

Please sign in to comment.