Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
13 / 13 |
| AbstractImageAssetFileFilter | |
100.00% |
1 / 1 |
|
100.00% |
4 / 4 |
7 | |
100.00% |
13 / 13 |
| __construct | |
100.00% |
1 / 1 |
2 | |
100.00% |
4 / 4 |
|||
| filterAssetFile | |
100.00% |
1 / 1 |
2 | |
100.00% |
8 / 8 |
|||
| assetFileShouldBeOptimize | |
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
|||
| optimizeImage | |
100.00% |
1 / 1 |
1 | n/a |
0 / 0 |
||||
| <?php | |
| namespace AssetsBundle\AssetFile\AssetFileFilter\ImageAssetFileFilter; | |
| abstract class AbstractImageAssetFileFilter extends \AssetsBundle\AssetFile\AssetFileFilter\AbstractAssetFileFilter { | |
| /** | |
| * @var boolean | |
| */ | |
| protected $imagecreatefromstringExists = false; | |
| /** | |
| * Constructor | |
| * @param array $oOptions | |
| */ | |
| public function __construct($oOptions = null) { | |
| parent::__construct($oOptions); | |
| //Check if imagecreatefromstring function exists | |
| if (function_exists('imagecreatefromstring')) { | |
| $this->imagecreatefromstringExists = true; | |
| } | |
| } | |
| /** | |
| * @param string $sImagePath | |
| * @see \AssetsBundle\Service\Filter\FilterInterface::run() | |
| * @throws \InvalidArgumentException | |
| * @throws \RuntimeException | |
| * @return string | |
| */ | |
| public function filterAssetFile(\AssetsBundle\AssetFile\AssetFile $oAssetFile) { | |
| //If asset file should not be optimize, return current content | |
| if (!$this->assetFileShouldBeOptimize($oAssetFile)) { | |
| return $oAssetFile->getAssetFileContents(); | |
| } | |
| //Optimize image | |
| \Zend\Stdlib\ErrorHandler::start(); | |
| $oImage = imagecreatefromstring($oAssetFile->getAssetFileContents()); | |
| imagealphablending($oImage, false); | |
| imagesavealpha($oImage, true); | |
| \Zend\Stdlib\ErrorHandler::stop(true); | |
| return $this->optimizeImage($oImage); | |
| } | |
| /** | |
| * @param \AssetsBundle\AssetFile\AssetFile $oAssetFile | |
| * @return boolean | |
| */ | |
| protected function assetFileShouldBeOptimize(\AssetsBundle\AssetFile\AssetFile $oAssetFile) { | |
| return $this->imagecreatefromstringExists && !!$oAssetFile->getAssetFileContents(); | |
| } | |
| /** | |
| * @param resource $oImage | |
| * @return string | |
| */ | |
| protected abstract function optimizeImage($oImage); | |
| } |