1: <?
2: namespace RM\AssetsCollector\Compilers;
3:
4: use \Nette\FileNotFoundException,
5: \Nette\Templating\Helpers,
6: \RM\AssetsCollector;
7:
8: 9: 10: 11: 12: 13: 14:
15: class ImageToDataStream extends BaseCssAssetsCompiler implements IAssetsCompiler
16: {
17:
18: public $maxSize;
19:
20: 21: 22: 23: 24: 25:
26: public function compile($input,$dir=null)
27: {
28: $this->input = $this->output = $input;
29: $images = $this->getImages();
30: if ($images) {
31: foreach($images as $img) {
32: $source_file = AssetsCollector::findFile($img,array($dir,$this->cssPath,$this->wwwDir));
33: if (filesize($source_file)<$this->maxSize) {
34: $imgbinary = fread(fopen($source_file, "r"), filesize($source_file));
35: $this->output = str_replace($img,\Nette\Templating\Helpers::dataStream($imgbinary),$this->output);
36: }
37: }
38: }
39: return $this->output;
40: }
41: }
42: