Skip to content

Commit

Permalink
Merge f8a05ce into f521d45
Browse files Browse the repository at this point in the history
  • Loading branch information
christeredvartsen committed Dec 26, 2013
2 parents f521d45 + f8a05ce commit 107ee44
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions ChangeLog.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ __N/A__

Bug fixes:

* #237: Fixed possible PHP Warnings when the transformation query parameter is invalid
* #222: Some images are not correctly identified
* #211: CORS event listener suppresses "405 Method not allowed" responses when enabled

Expand Down
4 changes: 3 additions & 1 deletion docs/usage/image-transformations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ Transforming images on the fly

What you as an end-user of an Imbo installation will be doing most of the time, is working with images. This is what Imbo was originally made for, and this chapter includes details about all the different image transformations Imbo supports.

All image transformations can be triggered by specifying the ``t`` query parameter. This parameter must be used as an array so that you can provide several image transformations. The transformations will be applied to the image in the same order as they appear in the URL.
All image transformations can be triggered by specifying the ``t`` query parameter. This parameter must be used as an array so that you can provide several image transformations. The transformations will be applied to the image in the same order as they appear in the URL. Each element in this array represents a single transformation with optional parameters, specified as a string. If the ``t`` query parameter is not an array or if any of its elements are not strings, Imbo will respond with ``HTTP 400``.

Below you will find all image transformations supported "out of the box", along with their parameters. Some transformations are rarely used with ``HTTP GET``, but are instead used by event listeners that transform images when they are added to Imbo (``HTTP POST``). If this is the case it will be mentioned in the description of the transformation.

.. _auto-rotate-transformation:

Expand Down
8 changes: 8 additions & 0 deletions library/Imbo/Http/Request/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,15 @@ public function getTransformations() {

$transformations = $this->query->get('t', array());

if (!is_array($transformations)) {
throw new InvalidArgumentException('Transformations must be specifed as an array', 400);
}

foreach ($transformations as $transformation) {
if (!is_string($transformation)) {
throw new InvalidArgumentException('Invalid transformation', 400);
}

// See if the transformation has any parameters
$pos = strpos($transformation, ':');
$urlParams = '';
Expand Down
35 changes: 34 additions & 1 deletion tests/ImboUnitTest/Http/Request/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function testGetTransformationsWithCorrectOrder() {
$request = new Request($query);
$transformations = $request->getTransformations();
$this->assertEquals('flipHorizontally', $transformations[0]['name']);
$this->assertEquals('flipVertically', $transformations[1]['name']);
$this->assertEquals('flipVertically', $transformations[1]['name']);
}

/**
Expand Down Expand Up @@ -172,4 +172,37 @@ public function testCanSetAndGetARoute() {
$this->assertSame($this->request, $this->request->setRoute($route));
$this->assertSame($route, $this->request->getRoute());
}

/**
* @expectedException Imbo\Exception\InvalidArgumentException
* @expectedExceptionMessage Transformations must be specifed as an array
* @expectedExceptionCode 400
* @covers Imbo\Http\Request\Request::getTransformations
*/
public function testRequiresTransformationsToBeSpecifiedAsAnArray() {
$request = new Request(array(
't' => 'desaturate',
));
$request->getTransformations();
}

/**
* @expectedException Imbo\Exception\InvalidArgumentException
* @expectedExceptionMessage Invalid transformation
* @expectedExceptionCode 400
* @covers Imbo\Http\Request\Request::getTransformations
*/
public function testDoesNotGenerateWarningWhenTransformationIsNotAString() {
$query = array(
't' => array(
array(
'flipHorizontally',
'flipVertically',
),
),
);

$request = new Request($query);
$request->getTransformations();
}
}

0 comments on commit 107ee44

Please sign in to comment.