Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
50.00% covered (danger)
50.00%
1 / 2
CRAP
83.33% covered (warning)
83.33%
5 / 6
GifImageAssetFileFilter
0.00% covered (danger)
0.00%
0 / 1
50.00% covered (danger)
50.00%
1 / 2
4.07
83.33% covered (warning)
83.33%
5 / 6
 assetFileShouldBeOptimize
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 optimizeImage
0.00% covered (danger)
0.00%
0 / 1
2.03
80.00% covered (warning)
80.00%
4 / 5
<?php
namespace AssetsBundle\AssetFile\AssetFileFilter\ImageAssetFileFilter;
class GifImageAssetFileFilter extends \AssetsBundle\AssetFile\AssetFileFilter\ImageAssetFileFilter\AbstractImageAssetFileFilter {
    /**
     * @var string
     */
    protected $assetFileFilterName = 'Gif';
    /**
     * @param \AssetsBundle\AssetFile\AssetFile $oAssetFile
     * @return boolean
     */
    protected function assetFileShouldBeOptimize(\AssetsBundle\AssetFile\AssetFile $oAssetFile) {
        //Check if image is not an animated Gif
        return parent::assetFileShouldBeOptimize($oAssetFile) && !preg_match('#(\x00\x21\xF9\x04.{4}\x00\x2C.*){2,}#s', $oAssetFile->getAssetFileContents());
    }
    /**
     * @param ressource $oImage
     * @return string
     * @throws \InvalidArgumentException
     */
    public function optimizeImage($oImage) {
        if (is_resource($oImage)) {
            ob_start();
            imagegif($oImage);
            return ob_get_clean();
        }
        throw new \InvalidArgumentException('Image expects a ressource, "' . gettype($oImage) . '" given');
    }
}