Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
9 / 9 |
| AbstractImageAssetFileFilter | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
9 / 9 |
| filterContent | |
100.00% |
1 / 1 |
2 | |
100.00% |
8 / 8 |
|||
| assetFileShouldBeOptimize | |
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
|||
| optimizeImage | n/a |
0 / 0 |
1 | n/a |
0 / 0 |
|||||
| <?php | |
| namespace AssetsBundle\AssetFile\AssetFileFilter\ImageAssetFileFilter; | |
| abstract class AbstractImageAssetFileFilter extends \AssetsBundle\AssetFile\AssetFileFilter\AbstractAssetFileFilter | |
| { | |
| /** | |
| * @param string $sContent | |
| * @param string $sFilePath | |
| * @return string | |
| */ | |
| protected function filterContent(string $sContent, string $sFilePath) : string | |
| { | |
| // If asset file should not be optimized, return raw content | |
| if (!$this->assetFileShouldBeOptimize($sContent)) { | |
| return $sContent; | |
| } | |
| // Optimize image | |
| \Zend\Stdlib\ErrorHandler::start(\E_ALL); | |
| $rImage = imagecreatefromstring($sContent); | |
| imagealphablending($rImage, false); | |
| imagesavealpha($rImage, true); | |
| \Zend\Stdlib\ErrorHandler::stop(true); | |
| return $this->optimizeImage($rImage); | |
| } | |
| /** | |
| * @param string $sContent | |
| * @return bool | |
| */ | |
| protected function assetFileShouldBeOptimize(string $sContent) : bool | |
| { | |
| return $sContent && function_exists('imagecreatefromstring'); | |
| } | |
| /** | |
| * @param resource $rImage | |
| * @return string | |
| */ | |
| abstract protected function optimizeImage($rImage) : string; | |
| } |