diff --git a/app/config/eccube/packages/eccube.yaml b/app/config/eccube/packages/eccube.yaml index 907d1c51d27..7986d3da160 100644 --- a/app/config/eccube/packages/eccube.yaml +++ b/app/config/eccube/packages/eccube.yaml @@ -124,3 +124,6 @@ parameters: eccube_result_cache_lifetime: 3600 # doctrineのresult cacheのlifetime. eccube_result_cache_lifetime_short: 10 # doctrineのresult cacheのlifetime. 商品一覧画面など長期間キャッシュできない箇所で使用する. eccube_content_maintenance_file_path: '%env(ECCUBE_MAINTENANCE_FILE_PATH)%' + eccube_product_image_resize: false + eccube_product_image_jpg_quality: 75 + eccube_product_image_png_quality: 6 diff --git a/src/Eccube/Controller/Admin/Product/ProductController.php b/src/Eccube/Controller/Admin/Product/ProductController.php index 90fa68b9694..0dced13bb8a 100644 --- a/src/Eccube/Controller/Admin/Product/ProductController.php +++ b/src/Eccube/Controller/Admin/Product/ProductController.php @@ -173,7 +173,7 @@ public function index(Request $request, $page_no = null, Paginator $paginator) * - デフォルト値 * また, セッションに保存する際は mtb_page_maxと照合し, 一致した場合のみ保存する. **/ - $page_count = $this->session->get('eccube.admin.order.search.page_count', + $page_count = $this->session->get('eccube.admin.product.search.page_count', $this->eccubeConfig->get('eccube_default_page_count')); $page_count_param = (int) $request->get('page_count'); @@ -183,7 +183,7 @@ public function index(Request $request, $page_no = null, Paginator $paginator) foreach ($pageMaxis as $pageMax) { if ($page_count_param == $pageMax->getName()) { $page_count = $pageMax->getName(); - $this->session->set('eccube.admin.order.search.page_count', $page_count); + $this->session->set('eccube.admin.product.search.page_count', $page_count); break; } } @@ -330,9 +330,64 @@ public function addImage(Request $request) throw new UnsupportedMediaTypeHttpException(); } - $filename = date('mdHis').uniqid('_').'.'.$extension; - $image->move($this->eccubeConfig['eccube_temp_image_dir'], $filename); - $files[] = $filename; + // リサイズ処理の可否('eccube_product_image_resize') + if ($this->eccubeConfig->get('eccube_product_image_resize')) { + + // 加工前の画像の情報を取得 + list($origin_w, $origin_h, $type) = getimagesize($image); + + // 加工前のファイルをフォーマット別に読み出す + switch ($type) { + case IMAGETYPE_JPEG: + $origin_image = imagecreatefromjpeg($image); + break; + + case IMAGETYPE_PNG: + $origin_image = imagecreatefrompng($image); + break; + + case IMAGETYPE_GIF: + $origin_image = imagecreatefromgif($image); + break; + + default: + throw new RuntimeException('対応していないファイル形式です。: ', $type); + } + + // 新しく描画するキャンバスを作成 + $canvas = imagecreatetruecolor($origin_w, $origin_h); + imagecopyresampled($canvas, $origin_image, 0,0,0,0, $origin_w, $origin_h, $origin_w, $origin_h); + + $filename = date('mdHis').uniqid('_').'.'.$extension; + $files[] = $filename; + + // 保存先を指定 + $resize_path = $this->eccubeConfig['eccube_temp_image_dir'] . '/' . $filename; + + // 画像形式ごとの処理 + switch ($type) { + case IMAGETYPE_JPEG: + imagejpeg($canvas, $resize_path, $this->eccubeConfig->get('eccube_product_image_jpg_quality')); + break; + + case IMAGETYPE_PNG: + imagepng($canvas, $resize_path, $this->eccubeConfig->get('eccube_product_image_png_quality')); + break; + + case IMAGETYPE_GIF: + imagegif($canvas, $resize_path); + break; + } + + imagedestroy($origin_image); + imagedestroy($canvas); + + } else { + + $filename = date('mdHis').uniqid('_').'.'.$extension; + $image->move($this->eccubeConfig['eccube_temp_image_dir'], $filename); + $files[] = $filename; + } } } }