-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a24cb0
commit da91c7e
Showing
6 changed files
with
150 additions
and
1 deletion.
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
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,64 @@ | ||
<?php | ||
/** | ||
* This file is part of the Cloudinary PHP package. | ||
* | ||
* (c) Cloudinary | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Cloudinary\Transformation; | ||
|
||
use Cloudinary\Transformation\Argument\ColorValue; | ||
use Cloudinary\Transformation\Expression\Expression; | ||
use InvalidArgumentException; | ||
|
||
/** | ||
* Class CropPad | ||
* | ||
* @internal | ||
*/ | ||
class CropPad extends Crop | ||
{ | ||
use CropPadTrait; | ||
use BackgroundTrait; | ||
|
||
/** | ||
* CropPad constructor. | ||
* | ||
* @param string|CropMode $cropMode | ||
* @param int|string|Expression $width | ||
* @param int|string|Expression $height | ||
* @param mixed $gravity | ||
* @param string|Background|ColorValue $background | ||
*/ | ||
public function __construct($cropMode, $width = null, $height = null, $gravity = null, $background = null) | ||
{ | ||
if ($gravity === null) { | ||
$gravity = Gravity::auto(); | ||
} | ||
|
||
parent::__construct($cropMode, $width, $height, $gravity); | ||
|
||
$this->background($background); | ||
} | ||
|
||
/** | ||
* Sets the gravity to use when using the FILL_PAD crop mode. | ||
* | ||
* @param $autoGravity | ||
* | ||
* @return $this | ||
*/ | ||
public function gravity($autoGravity) | ||
{ | ||
if (! $autoGravity instanceof AutoGravity) { | ||
throw new InvalidArgumentException('CropPad only supports Auto Gravity'); | ||
} | ||
|
||
$this->addQualifier($autoGravity); | ||
|
||
return $this; | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
/** | ||
* This file is part of the Cloudinary PHP package. | ||
* | ||
* (c) Cloudinary | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Cloudinary\Transformation; | ||
|
||
use Cloudinary\Transformation\Argument\ColorValue; | ||
|
||
/** | ||
* Trait CropPadTrait | ||
* | ||
* @api | ||
*/ | ||
trait CropPadTrait | ||
{ | ||
/** | ||
* Tries to prevent a "bad crop" by first attempting to use the auto cropping mode, but adding some padding if the | ||
* algorithm determines that more of the original image needs to be included in the final image. | ||
* | ||
* Especially useful if the aspect ratio of the delivered image is considerably different from the original's | ||
* aspect ratio. | ||
* | ||
* Only supported in conjunction with Automatic cropping (Gravity::auto()) | ||
* | ||
* @param int|float|string|null $width The required width of a transformed asset. | ||
* @param int|float|null $height The required height of a transformed asset. | ||
* @param FocalGravity|string $gravity Specifies which part of the original image to include. | ||
* @param Background|ColorValue|string $background The background color of the image. | ||
* | ||
* @return CropPad | ||
* | ||
* @see Gravity::auto | ||
*/ | ||
public static function autoPad($width = null, $height = null, $gravity = null, $background = null) | ||
{ | ||
return new CropPad(CropMode::AUTO_PAD, $width, $height, $gravity, $background); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,5 +23,6 @@ trait ResizeTrait | |
use FillTrait; | ||
use FillPadTrait; | ||
use CropTrait; | ||
use CropPadTrait; | ||
use ImaggaTrait; | ||
} |
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