-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- [R] PHP 7.4 & PHP 8.0 compatible version - [+] `applyImageFilter` method - [+] GDImageException class
- Loading branch information
Karel Wintersky
committed
Aug 27, 2024
1 parent
d911e11
commit e5cd3ca
Showing
6 changed files
with
195 additions
and
16 deletions.
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
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,35 @@ | ||
<?php | ||
|
||
namespace AJUR\Wrappers; | ||
|
||
class GDImageException extends \RuntimeException | ||
{ | ||
protected array $_info; | ||
|
||
public function __construct(string $message = "", int $code = 0 , array $info = []) | ||
{ | ||
$this->_info = $info; | ||
|
||
parent::__construct($message, $code, null); | ||
} | ||
|
||
/** | ||
* Get custom field | ||
* | ||
* @param $key | ||
* @return array|mixed|null | ||
*/ | ||
public function getInfo($key = null) | ||
{ | ||
return | ||
is_null($key) | ||
? $this->_info | ||
: (array_key_exists($key, $this->_info) ? $this->_info[$key] : null); | ||
} | ||
|
||
public function getError() | ||
{ | ||
return 'Exception thrown from [' . $this->getFile() . '] with message: [' . $this->getMessage() . '] at line # ' . $this->getLine(); | ||
} | ||
|
||
} |
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
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,110 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/vendor/autoload.php'; | ||
|
||
use AJUR\Wrappers\GDWrapper; | ||
use AJUR\Wrappers\GDWrapperInterface; | ||
|
||
if (!is_readable(__DIR__ . '/test.jpg')) { | ||
die(PHP_EOL . PHP_EOL . 'Any `test.jpg` is needed for testing' . PHP_EOL . PHP_EOL); | ||
} | ||
|
||
GDWrapper::init([ | ||
'JPEG_COMPRESSION_QUALITY' => 80, | ||
'WEBP_COMPRESSION_QUALITY' => 100, | ||
'PNG_COMPRESSION_QUALITY' => 0 | ||
]); | ||
|
||
echo 'Making watermark file' . PHP_EOL; | ||
GDWrapper::resizeImageAspect('test.jpg', 'watermark.png', 100, 100); | ||
$wm = GDWrapper::applyImageFilter('watermark.png', IMG_FILTER_NEGATE); | ||
$wm->store()->destroyImage(); | ||
|
||
echo "cropImage: " . PHP_EOL; | ||
var_dump( | ||
GDWrapper::cropImage('test.jpg', 'test_crop.jpg', [ 100, 100], [ 900, 900 ], [ 900, 900 ], 70) | ||
); | ||
|
||
echo "resizeImageAspect: " . PHP_EOL; | ||
var_dump( | ||
GDWrapper::resizeImageAspect('test.jpg', 'test_RIA.png', 700, 200) | ||
); | ||
|
||
echo "resizeImageAspect: " . PHP_EOL; | ||
var_dump( | ||
GDWrapper::resizeImageAspect('test.jpg', 'test_RIA.jpg', 200, 500, 40) | ||
); | ||
|
||
echo "resizePictureAspect: " . PHP_EOL; | ||
var_dump( | ||
GDWrapper::resizePictureAspect('test.jpg', 'test_RPA.png', 700, 200) | ||
); | ||
|
||
echo "resizePictureAspect: " . PHP_EOL; | ||
var_dump( | ||
GDWrapper::resizePictureAspect('test.jpg', 'test_RPA.jpg', 200, 500, 40) | ||
); | ||
|
||
echo "verticalImage: " . PHP_EOL; | ||
var_dump( | ||
GDWrapper::verticalImage('test.jpg', 'test_VI.jpg', 300, 300, 80) | ||
); | ||
|
||
echo "getFixedPicture: " . PHP_EOL; | ||
var_dump( | ||
GDWrapper::getFixedPicture('test.jpg', 'test_GFP.jpg', 470, 370, 90) | ||
); | ||
|
||
echo "addWaterMark: " . PHP_EOL; | ||
var_dump( | ||
GDWrapper::addWaterMark('test.jpg', ['watermark' => 'watermark.png', 'margin' => 10] , GDWrapperInterface::WM_POSITION_LEFT_TOP, null, 'test-wm-10.jpg') | ||
); | ||
|
||
|
||
echo "addWaterMark: " . PHP_EOL; | ||
var_dump( | ||
GDWrapper::addWaterMark('test.jpg', ['watermark' => 'watermark.png', 'margin' => 20] , GDWrapperInterface::WM_POSITION_RIGHT_BOTTOM, null, 'test-wm-20.jpg') | ||
); | ||
|
||
echo "addWaterMark: " . PHP_EOL; | ||
var_dump( | ||
GDWrapper::addWaterMark('test.jpg', ['watermark' => 'watermark.png', 'margin' => 50] , GDWrapperInterface::WM_POSITION_LEFT_BOTTOM, null, 'test-wm-50.jpg') | ||
); | ||
|
||
echo "addWaterMark: " . PHP_EOL; | ||
var_dump( | ||
GDWrapper::addWaterMark('test.jpg', ['watermark' => '_watermark_m.png', 'margin' => 50] , GDWrapperInterface::WM_POSITION_LEFT_BOTTOM, null, 'test-2.jpg') | ||
); | ||
|
||
echo "rotate: " . PHP_EOL; | ||
var_dump( | ||
GDWrapper::rotate('test.jpg', 'left', 90, 'test_kid_rotate90.jpg') | ||
); | ||
|
||
echo "cropImage: " . PHP_EOL; | ||
var_dump( | ||
GDWrapper::cropImage('test.jpg', 'test_crop.jpg', [ 100, 100 ] , [ 800, 1000 ], [ 1000, 1000 ], 90) | ||
); | ||
|
||
echo "resizeImageAspect: " . PHP_EOL; | ||
var_dump( | ||
GDWrapper::resizeImageAspect('test.jpg', 'test_RIA.jpg', 200, 500, 40) | ||
); | ||
|
||
echo "imageFillColor: " . PHP_EOL; | ||
var_dump( | ||
GDWrapper::imageFillColor('test_red.png', 500, 500, [ 255 ], 90) | ||
); | ||
|
||
echo "imageFillColor: " . PHP_EOL; | ||
var_dump( | ||
GDWrapper::imageFillColor('test_yellow.webp', 500, 500, [ 255, 255 ], 90) | ||
); | ||
|
||
|
||
/* | ||
$f = new \AJUR\Wrappers\GDImageInfo('test.jpg'); | ||
$f->changeExtension('webp'); | ||
var_dump($f->filename); | ||
*/ | ||
|