/** * @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; }
/** * @Route("/ajax/edit", name="goods_ajax_edit", options={"expose"=true}) */ public function goodsAjaxEditAction(Request $request) { if (!$this->postCRSFCheck($request)) { return new Response('error'); } foreach ($request->request->keys() as $key) { ${$key} = $request->request->get($key); } $em = $this->getDoctrine()->getManager(); $em->getConnection()->beginTransaction(); try { $oUser = $this->get('security.token_storage')->getToken()->getUser(); $userStore = $oUser->getStore(); $sStoreSn = $userStore->getSn(); $nGoodsLevelId = $goods_search_goods_level[0]; $oGoodsPassport = $em->find('WoojinGoodsBundle:GoodsPassport', $nGoodsPassportId); $sym = $this->get('base_method')->getSymbol(); $theRate = $sym == 'NT' ? self::SN_RATE : 10; $sGoodsCost = isset($sGoodsCost) ? $sGoodsCost : $oGoodsPassport->getCost(); $sGoodsPrice = isset($sGoodsPrice) ? $sGoodsPrice : $oGoodsPassport->getPrice(); $sGoodsSn = $oGoodsPassport->genSn($sStoreSn); $oGoodsLevel = $this->getDoctrine()->getRepository('WoojinGoodsBundle:GoodsLevel')->find($nGoodsLevelId); $oGoodsMT = $this->getDoctrine()->getRepository('WoojinGoodsBundle:GoodsMT')->find($nGoodsMTId); $oGoodsSource = $this->getDoctrine()->getRepository('WoojinGoodsBundle:GoodsSource')->find($nGoodsSourceId); $oImg = $oGoodsPassport->getImg(); $sOldCreatedAt = is_null($oGoodsPassport->getCreatedAt()) ? null : $oGoodsPassport->getCreatedAt()->format('Y-m-d'); $sMsg = '修改商品資訊:[' . $nGoodsPassportId . ']'; $sMsg .= '{產編:[' . $oGoodsPassport->getSn() . '][' . $sGoodsSn . ']}'; $sMsg .= '{品名:[' . $oGoodsPassport->getName() . '][' . $sGoodsName . ']}'; $sMsg .= '{序號:[' . $oGoodsPassport->getOrgSn() . '][' . $sGoodsOrgSn . ']}'; $sMsg .= '{成本:[' . $oGoodsPassport->getCost() . '][' . $sGoodsCost . ']}'; $sMsg .= '{訂價:[' . $oGoodsPassport->getPrice() . '][' . $sGoodsPrice . ']}'; //$sMsg.= '{品牌:['.$oGoodsPassport->getBrandSn()->getBrandSnName().']['; $sMsg .= $oGoodsPassport->getModel() . ']}'; $sMsg .= '{新舊:[' . $oGoodsPassport->getLevel()->getName() . '][' . $oGoodsLevel->getName() . ']}'; $sMsg .= '{進貨時間:[' . $sOldCreatedAt . '][' . $sCreatedAt . ']}'; if ($oGoodsPassport->getSource()) { $sMsg .= '{來源:[' . $oGoodsPassport->getSource()->getName() . '][' . $oGoodsSource->getName() . ']}'; } $sMsg .= '{備註:[' . $oGoodsPassport->getMemo() . '][' . $sGoodsMemo . ']}'; $oMetaRecord = $this->get('my_meta_record_method'); $oMetaRecord->recordMeta($sMsg); $color = $em->find('WoojinGoodsBundle:Color', $color); $pattern = $em->find('WoojinGoodsBundle:Pattern', $pattern); $brand = $em->find('WoojinGoodsBundle:Brand', $brand); $oGoodsPassport->setColor($color)->setPattern($pattern)->setColorSn($colorSn)->setModel($model)->setBrand($brand)->setLevel($oGoodsLevel)->setSource($oGoodsSource)->setName($sGoodsName)->setSn($sGoodsSn)->setOrgSn($sGoodsOrgSn)->setCost($sGoodsCost)->setPrice($sGoodsPrice)->setMt($oGoodsMT)->setCreatedAt(new \DateTime($sCreatedAt))->setMemo($sGoodsMemo); $files = $request->files->get('img'); if ($files) { $sMsg .= '{圖片修改}'; $sRoot = $request->server->get('DOCUMENT_ROOT'); $sDirHead = '/img/' . date('Y-m') . '/'; $sDirHeadRoot = $sRoot . $sDirHead; $sImgName = $nGoodsPassportId . $files->getClientOriginalName(); $sWebSrc = $sDirHead . $sImgName; if (!is_dir($sDirHeadRoot)) { mkdir($sDirHeadRoot); } $oImg = $oGoodsPassport->getImg(); if ($oImg) { $sFilePath = $sRoot . $oImg->getPath(); if (file_exists($sFilePath)) { unlink($sFilePath); } } else { $oImg = new Img(); } if ($files->move($sDirHeadRoot, $sImgName)) { $oImg->setPath($sWebSrc); $em->persist($oImg); $em->flush(); $nImgId = $oImg->getImgId(); } $oGoodsPassport->setImg($oImg); $sImgPath = $oGoodsPassport->getImg()->getPath(); } else { if (isset($oImg)) { $nImgId = $oGoodsPassport->getImg()->getId(); $sImgPath = $oGoodsPassport->getImg()->getPath(); } } $em->persist($oGoodsPassport); $em->flush(); $em->getConnection()->commit(); } catch (Exception $e) { $em->getConnection()->rollback(); throw $e; } $h['sGoodsSn'] = $sGoodsSn; if (!isset($nImgId)) { $nImgId = ''; } $h['nImgId'] = $nImgId; if (!isset($sImgPath)) { $sImgPath = '/img/nothing.png'; } $h['sImgPath'] = $sImgPath; return new Response(json_encode($h)); }