public function run() { trigger('imerge_start', $this); mark('开始自动合图扫描', 'emphasize'); $files = get_files_by_type(C('SRC.SRC_PATH'), 'css'); $generator = new MergeConfigGenerator($files); $generator->generate(); $writer = new MergeConfigWriter(C('IMERGE_PATH')); $writer->writeImageConfig($generator->getConfig()); // 更新大图 $this->updateSprite(); trigger('imerge_end', $this); }
/** * 导出配置 * 包括belongMap,md5Map,revision */ public static function export() { $path = C('INCRE.PATH') . '/' . C('INCRE.MAP_FILENAME'); contents_to_file($path, MergeConfigWriter::configStringify(self::$belongMap)); $path = C('INCRE.PATH') . '/' . C('INCRE.MD5_FILENAME'); contents_to_file($path, MergeConfigWriter::configStringify(self::$md5Map)); $path = C('INCRE.PATH') . '/' . C('INCRE.VER_FILENAME'); contents_to_file($path, self::$revision); }
/** * 绘制图像 * @param $type */ public function draw($type, $config = array()) { if (empty($config)) { $loader = new MergeConfigLoader($this->imergePath); $config = $loader->getImageConfigByType($type); } $imgList = array(); if (!empty($config)) { foreach ($config as $key => $value) { try { $imgList[$key] = new Image($this->staticRelativePath . $key, $value); } catch (ImageException $e) { mark("合图{$type}中,存在小图{$key}的配置文件,但该小图不存在,请到合图配置界面删除该小图", 'warn'); } } } $layout = new Layout($imgList); $spriteConfigs = array(); $spriteConfigs[$type] = array(); if ($layout->reflow($width, $height)) { $this->sprite = imagecreatetruecolor($width, $height); imagealphablending($this->sprite, false); imagesavealpha($this->sprite, true); imagefill($this->sprite, 0, 0, imagecolorallocatealpha($this->sprite, 0, 0, 0, 127)); $spriteConfigs[$type]['config'] = $this->repaint($this->sprite, $imgList, $width, $height); // 记录sprite的属性 $spriteConfigs[$type]['attr'] = array('filename' => $type . C('SPRITE_SUFFIX') . '.png', 'width' => $width, 'height' => $height); // $spriteConfigs[$type]['filename'] = $type.C('SPRITE_SUFFIX').'.png'; // 生成大图到imerge_sprite_dir $path = $this->imergePath . '/' . C('IMERGE_SPRITE_DIR') . '/' . $type . C('SPRITE_SUFFIX') . '.png'; imagepng($this->sprite, $path); // 写入配置 $writer = new MergeConfigWriter($this->imergePath); $writer->writeSpriteConfig($spriteConfigs); // 派发处理完成事件 trigger('DRAW_SPRITE_END', $path); } }