예제 #1
0
파일: Cli.php 프로젝트: cargomedia/cm
 public function generateFavicon()
 {
     $faviconConfigList = $this->_getFaviconConfigList();
     $this->_getStreamOutput()->writeln('Generating favicons');
     $themeDirStructList = Functional\map(CM_Site_Abstract::getAll(), function (CM_Site_Abstract $site) {
         $render = new CM_Frontend_Render(new CM_Frontend_Environment($site));
         return ['render' => $render, 'themeDir' => new CM_File($render->getThemeDir(true))];
     });
     $themeDirStructList = Functional\unique($themeDirStructList, function (array $themeDirStruct) {
         /** @var CM_File $themeDir */
         $themeDir = $themeDirStruct['themeDir'];
         return $themeDir->getPath();
     });
     //filter site aliases
     foreach ($themeDirStructList as $themeDirStruct) {
         /** @var CM_Frontend_Render $render */
         $render = $themeDirStruct['render'];
         /** @var CM_File $themeDir */
         $themeDir = $themeDirStruct['themeDir'];
         $svgFile = $themeDir->joinPath('resource', 'img', self::FAVICON_SVG_FILENAME);
         if ($svgFile->exists()) {
             foreach ($faviconConfigList as $outputFilename => $config) {
                 $backgroundWidth = (int) $config['width'];
                 $backgroundHeight = (int) $config['height'];
                 $backgroundColor = false === $config['transparent'] ? $render->getLessVariable(self::FAVICON_BACKGROUND_LESS_VARIABLE) : 'transparent';
                 $background = new Imagick();
                 $background->newPseudoImage($backgroundWidth, $backgroundHeight, 'canvas:' . $backgroundColor);
                 $backgroundImage = new CM_Image_Image($background);
                 $iconSize = (int) (min($backgroundWidth, $backgroundHeight) * (double) $config['iconSize']);
                 $iconImage = CM_Image_Image::createFromSVGWithSize($svgFile->read(), $iconSize, $iconSize);
                 $backgroundImage->compositeImage($iconImage, ($backgroundWidth - $iconSize) / 2, ($backgroundHeight - $iconSize) / 2);
                 $backgroundImage->setFormat(CM_Image_Image::FORMAT_PNG);
                 $targetFile = $themeDir->joinPath('resource', 'img', 'meta', $outputFilename);
                 $targetFile->ensureParentDirectory();
                 $targetFile->write($backgroundImage->getBlob());
                 $this->_getStreamOutput()->writeln('Generated ' . $targetFile->getPath());
             }
         }
     }
 }
예제 #2
0
파일: ImageTest.php 프로젝트: cargomedia/cm
 public function testCompositeImage()
 {
     $backgroundColor = '#0000FF';
     $background = new \Imagick();
     $background->newPseudoImage(100, 100, 'canvas:' . $backgroundColor);
     $backgroundImage = new CM_Image_Image($background);
     $foregroundColor = '#FF0000';
     $foreground = new \Imagick();
     $foreground->newPseudoImage(30, 30, 'canvas:' . $foregroundColor);
     $foregroundImage = new CM_Image_Image($foreground);
     $backgroundImage->compositeImage($foregroundImage, 10, 10);
     $backgroundImagick = $this->_getImagickObject($backgroundImage);
     $colorBackground = $backgroundImagick->getImagePixelColor(9, 9)->getColor();
     $this->assertSame(0, $colorBackground['r']);
     $this->assertSame(0, $colorBackground['g']);
     $this->assertSame(255, $colorBackground['b']);
     $colorForeground = $backgroundImagick->getImagePixelColor(10, 10)->getColor();
     $this->assertSame(255, $colorForeground['r']);
     $this->assertSame(0, $colorForeground['g']);
     $this->assertSame(0, $colorForeground['b']);
 }