Overview

Namespaces

  • RM
    • AssetsCollector
      • Compilers

Classes

  • BaseAssetsCompiler
  • BaseCssAssetsCompiler
  • BaseJsAssetsCompiler
  • CssSimpleMinificator
  • ImageReplacer
  • ImageToDataStream

Interfaces

  • IAssetsCompiler
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?
 2: namespace RM\AssetsCollector\Compilers;
 3: 
 4: use \Nette\FileNotFoundException,
 5:     \Nette\Templating\Helpers,
 6:     \RM\AssetsCollector;
 7: 
 8: /**
 9:  * CSS compiler where replace images in content to data stream.
10:  *
11:  * @author Roman Mátyus
12:  * @copyright (c) Roman Mátyus 2012
13:  * @license MIT
14:  */
15: class ImageToDataStream extends BaseCssAssetsCompiler implements IAssetsCompiler
16: {
17:     /** @var int maximal size of processed image */
18:     public $maxSize;
19: 
20:     /**
21:      * Get compiled content
22:      * @param   input string
23:      * @param   dir null|string dir for find file by relative path
24:      * @return  output string
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: 
API documentation generated by ApiGen 2.8.0