/** * @param Img $img * @return boolean */ public function createRemoveBorder(Img $img) { /** * 圖片來源路徑(圖片路徑必須直接使用根路徑, 否則開不了) * * @var string */ $rootPath = $img->getPath(true); $fileName = $img->getPathNoBorder(true); // 2/3, 下, 左, 右 10px /** * 圖片物件 * * @var object */ $image = $this->imageHandling->open($rootPath); $this->imageHandling->open($rootPath)->resize(Avenue::IMG_WIDTH, Avenue::IMG_WIDTH)->rectangle(self::MARK_X_START_POS, self::MARK_Y_START_POS, self::MARK_X_END_POS, self::MARK_Y_END_POS, 'white', true)->rectangle(0, 0, Avenue::IMG_WIDTH, self::BORDER_WIDTH, 'white', true)->rectangle(0, Avenue::IMG_WIDTH - self::BORDER_WIDTH, Avenue::IMG_WIDTH, Avenue::IMG_WIDTH, 'white', true)->rectangle(0, 0, self::BORDER_WIDTH, Avenue::IMG_WIDTH, 'white', true)->rectangle(Avenue::IMG_WIDTH - self::BORDER_WIDTH, 0, Avenue::IMG_WIDTH, Avenue::IMG_WIDTH, 'white', true)->save($fileName, 'jpg', Avenue::DESIMG_CROP_QA); return true; }
public function getCacheImage(Img $img, $width, $height, $isForceOver = false) { $name = md5($img->getId()); $prefix = implode(str_split(substr($name, 0, 5)), '/'); $cachePath = 'cache/image/' . $prefix . '/' . $width . '/' . $height . '/' . $name . '.jpg'; if (file_exists($cachePath) && !$isForceOver) { return '/' . $cachePath; } /** * Gregwar 圖片處理 Service * * @var object */ $imageHandling = $this->container->get('image.handling'); $imageHandling->open($img->getPath())->resize($width, $height)->save($cachePath); return '/' . $cachePath; }