Ejemplo n.º 1
0
 /**
  * Get the target ImagePack via output file, 
  * which will auto be generated if not registered.
  * 
  * @param File $outputFile
  * @return ImagePack
  */
 public static function getImagePack(File $outputFile)
 {
     if (!\array_key_exists(\md5($outputFile->getAbsolutePath()), self::$packs)) {
         self::$packs[md5($outputFile->getAbsolutePath())] = new ImagePack($outputFile);
     }
     return self::$packs[md5($outputFile->getAbsolutePath())];
 }
Ejemplo n.º 2
0
 /**
  * Generate the Css Style Code for target background image.
  * 
  * @param string $imagePath
  * @param array $options
  */
 public function backgroundImage($imagePath, $options = array())
 {
     $image = new File($imagePath, $this->getResource()->getFile()->getAbsoluteFile()->getParent());
     $data = \getimagesize($image->getAbsolutePath());
     $manager = ProjectMapping::getManagerByProject($this->getResource()->getParentProject());
     $options = array_merge(array('scaleWidth' => "auto", 'scaleHeight' => "auto", 'canvasWidth' => "auto", 'canvasHeight' => "auto", 'tileDirection' => "none", 'packName' => "auto"), $options);
     $origWidth = $data[0];
     $origHeight = $data[1];
     $mime = \image_type_to_mime_type($data[2]);
     /* @var $scaleWidth int */
     $scaleWidth = $origWidth;
     if ($options['scaleWidth'] === "auto") {
         if (preg_match('/^\\d+(\\.\\d+){0,1}%$/', $options['scaleHeight'])) {
             $scaleWidth = \str_replace('%', '', $options['scaleHeight']) / 100 * $origWidth;
         }
     } elseif (preg_match('/^\\d+(\\.\\d+){0,1}%$/', $options['scaleWidth'])) {
         $scaleWidth = \str_replace('%', '', $options['scaleWidth']) / 100 * $origWidth;
     } elseif (preg_match('/^\\d+$/', $options["scaleWidth"])) {
         $scaleWidth = intval($options["scaleWidth"]);
     }
     if (preg_match('/^\\d+$/', $options["scaleHeight"])) {
         $scaleHeight = intval($options["scaleHeight"]);
     } elseif (preg_match('/^\\d+(\\.\\d+){0,1}%$/', $options['scaleHeight'])) {
         $scaleHeight = \str_replace('%', '', $options['scaleHeight']) / 100 * $origHeight;
     } else {
         $scaleHeight = $scaleWidth / $origWidth * $origHeight;
     }
     $canvasWidth = $scaleWidth;
     $canvasHeight = $scaleHeight;
     if (preg_match('/^\\d+$/', $options["canvasWidth"])) {
         $canvasWidth = intval($options["canvasWidth"]);
     }
     if (preg_match('/^\\d+$/', $options["canvasHeight"])) {
         $canvasHeight = intval($options["canvasHeight"]);
     }
     if ($options["tileDirection"] === "none" && $options["packName"] === "auto") {
         //
     }
     $this->getResource()->getParentProject()->getCacheManager()->searchCacheDir($manager->getDefaultImageOutputDir());
     var_dump($origWidth);
     var_dump($origHeight);
     var_dump($mime);
     var_dump($image->getAbsolutePath());
     var_dump($options["scaleWidth"]);
     var_dump($options["scaleHeight"]);
     var_dump($options["canvasWidth"]);
     var_dump($options["canvasHeight"]);
     var_dump($options["tileDirection"]);
     var_dump($options["packName"]);
     exit;
 }
Ejemplo n.º 3
0
 /**
  * Get the resource object with specific internal resource class.
  * @param File $file The resource as File Object.
  * @return TwigResourceFile The resource object from factory
  * @throws ResourceNotFoundException
  */
 protected function resourceFactory(File $file)
 {
     try {
         return new TwigResourceFile($file);
     } catch (\InvalidArgumentException $exc) {
         throw new ResourceNotFoundException($file->getAbsolutePath(), $this, null, $exc->getMessage());
     }
 }
 private function generateBowerComponentsFile(BundleInterface $bundle, File $outputFile)
 {
     /* @var $chiji_bundle BundleInterface */
     $chiji_bundle = $this->getApplication()->getKernel()->getBundle("ChigiChijiBundle");
     $templates_dir = new File("Resources/templates", $chiji_bundle->getPath());
     $twig = new \Twig_Environment(new \Twig_Loader_Filesystem($templates_dir->getAbsolutePath()));
     file_put_contents($outputFile->getAbsolutePath(), $twig->loadTemplate("BowerComponents.json.twig")->render(array("bundleName" => $bundle->getName())));
 }
Ejemplo n.º 5
0
 public function buildCache(AbstractResourceFile $resource)
 {
     $this->getParentProject()->getCacheManager()->registerDirectory($resource->getFile()->getAbsoluteFile()->getParentFile());
     $cache_dir = $this->getParentProject()->getCacheManager()->searchCacheDir($resource->getFile()->getAbsoluteFile()->getParentFile());
     if (\is_null($cache_dir) || $cache_dir->isFile()) {
         throw new CacheBuildFileException("[" . $this->getParentProject()->getProjectName() . "]Cache Build Failed: " . $resource->getFile()->getAbsolutePath());
     }
     if (!$cache_dir->exists()) {
         $cache_dir->mkdirs();
     }
     $cache_file = new File(substr($resource->getFile()->getName(), 0, -5), $cache_dir->getAbsolutePath());
     \file_put_contents($cache_file->getAbsolutePath(), $this->compile($resource));
     $this->getParentProject()->getCacheManager()->registerCache($resource, $cache_file);
 }
 /**
  * 
  * @param string $imagePath
  * @param array $options
  */
 public function backgroundImage($imagePath, $options = array())
 {
     $image = new File($imagePath, $this->getResource()->getFile()->getAbsoluteFile()->getParent());
     if (!$image->isFile()) {
         throw new FileNotProcessableException($imagePath);
     }
     $data = \getimagesize($image->getAbsolutePath());
     $manager = ProjectMapping::getManagerByProject($this->getResource()->getParentProject());
     $options = array_merge(array('scaleWidth' => "auto", 'scaleHeight' => "auto", 'canvasWidth' => "auto", 'canvasHeight' => "auto", "canvasPosX" => 0, "canvasPosY" => 0, 'tileDirection' => "none", 'packName' => "auto"), $options);
     $origWidth = $data[0];
     $origHeight = $data[1];
     /* @var $scaleWidth int */
     $scaleWidth = $origWidth;
     if ($options['scaleWidth'] === "auto") {
         if (\preg_match('/^\\d+(\\.\\d+){0,1}%$/', $options['scaleHeight'])) {
             $scaleWidth = \str_replace('%', '', $options['scaleHeight']) / 100 * $origWidth;
         }
     } elseif (\preg_match('/^\\d+(\\.\\d+){0,1}%$/', $options['scaleWidth'])) {
         $scaleWidth = \str_replace('%', '', $options['scaleWidth']) / 100 * $origWidth;
     } elseif (\preg_match('/^\\d+$/', $options["scaleWidth"])) {
         $scaleWidth = intval($options["scaleWidth"]);
     }
     if (\preg_match('/^\\d+$/', $options["scaleHeight"])) {
         $scaleHeight = intval($options["scaleHeight"]);
     } elseif (\preg_match('/^\\d+(\\.\\d+){0,1}%$/', $options['scaleHeight'])) {
         $scaleHeight = \str_replace('%', '', $options['scaleHeight']) / 100 * $origHeight;
     } else {
         $scaleHeight = $scaleWidth / $origWidth * $origHeight;
     }
     $canvasWidth = $scaleWidth;
     $canvasHeight = $scaleHeight;
     if (\preg_match('/^\\d+$/', $options["canvasWidth"])) {
         $canvasWidth = intval($options["canvasWidth"]);
     }
     if (\preg_match('/^\\d+$/', $options["canvasHeight"])) {
         $canvasHeight = intval($options["canvasHeight"]);
     }
     if (\preg_match('/^\\d+$/', $options["canvasPosX"])) {
         $canvasPosX = intval($options["canvasPosX"]);
     } elseif (strtolower($options["canvasPosX"]) === "center") {
         $canvasPosX = intval(($canvasWidth - $scaleWidth) / 2);
     } elseif (strtolower($options["canvasPosX"]) === "left") {
         $canvasPosX = 0;
     } elseif (strtolower($options["canvasPosX"]) === "right") {
         $canvasPosX = intval($canvasWidth - $scaleWidth);
     } else {
         $canvasPosX = 0;
     }
     if (\preg_match('/^\\d+$/', $options["canvasPosY"])) {
         $canvasPosY = intval($options["canvasPosY"]);
     } elseif (strtolower($options["canvasPosY"]) === "center") {
         $canvasPosY = intval(($canvasHeight - $scaleHeight) / 2);
     } elseif (strtolower($options["canvasPosY"]) === "top") {
         $canvasPosY = 0;
     } elseif (strtolower($options["canvasPosY"]) === "bottom") {
         $canvasPosY = intval($canvasHeight - $scaleHeight);
     } else {
         $canvasPosY = 0;
     }
     if ($options["tileDirection"] === "none" && $options["packName"] === "auto") {
         $output_dir = ProjectMapping::getManagerByProject($this->getResource()->getParentProject())->getDefaultImageOutputDir();
         $this->getResource()->getParentProject()->getCacheManager()->registerDirectory($output_dir);
         $cache_dir = $this->getResource()->getParentProject()->getCacheManager()->searchCacheDir($output_dir);
         if (!$cache_dir->exists()) {
             $cache_dir->mkdirs();
         }
         $imageUnit = new ImageUnit($image->getAbsolutePath(), $scaleWidth, $scaleHeight, $canvasWidth, $canvasHeight, $canvasPosX, $canvasPosY);
         $imagePack = PackUtil::getImagePack(new File(md5($this->getResource()->getRealPath()) . ".png", $cache_dir->getAbsolutePath()));
         $imagePack->push($imageUnit);
     }
     $replace_code = sha1(uniqid()) . ":" . sha1($this->getResource()->getRealPath()) . ";";
     RenderFixTaskQueue::getInstance()->push(new CssImagePackFix($this->getResource(), $replace_code, $imageUnit, $imagePack));
     return $replace_code;
 }