From 4d6ad6b04dc64da6c08d6edfa183d1359c22329e Mon Sep 17 00:00:00 2001 From: zero Date: Mon, 2 Apr 2007 05:14:28 +0000 Subject: [PATCH] git-svn-id: http://xe-core.googlecode.com/svn/trunk@882 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- classes/file/FileHandler.class.php | 91 ++++++++++++++++++++++++++++ common/js/common.js | 14 ++--- modules/member/member.controller.php | 81 ++----------------------- 3 files changed, 101 insertions(+), 85 deletions(-) diff --git a/classes/file/FileHandler.class.php b/classes/file/FileHandler.class.php index d6883d4b3..63982cdd5 100644 --- a/classes/file/FileHandler.class.php +++ b/classes/file/FileHandler.class.php @@ -100,5 +100,96 @@ if($size >1024 && $size< 1024 *1024) return sprintf("%0.1fKB",$size / 1024); return sprintf("%0.2fMB",$size / (1024*1024)); } + + /** + * @brief 특정 이미지 파일을 특정 위치로 옮김 (옮길때 이미지의 크기를 리사이징할 수 있음..) + **/ + function createImageFile($source_file, $target_file, $resize_width = 0, $resize_height = 0, $target_type = '') { + if(!file_exists($source_file)) return; + + // 이미지 정보를 구함 + list($width, $height, $type, $attrs) = getimagesize($source_file); + switch($type) { + case '1' : + $type = 'gif'; + break; + case '2' : + $type = 'jpg'; + break; + case '3' : + $type = 'png'; + break; + case '6' : + $type = 'bmp'; + break; + default : + return; + break; + } + + if(!$target_type) $target_type = $type; + $target_type = strtolower($target_type); + + // 이미지 정보가 정해진 크기보다 크면 크기를 바꿈 + $new_width = $width; + if($resize_width>0 && $new_width > $resize_width) $new_width = $resize_width; + $new_height = $height; + if($resize_height>0 && $new_height > $resize_height) $new_height = $resize_height; + + + // 업로드한 파일을 옮기지 않고 gd를 이용해서 gif 이미지를 만듬 (gif, jpg, png, bmp가 아니면 역시 무시) + $thumb = imagecreatetruecolor($new_width, $new_height); + switch($type) { + case 'gif' : + $source = imagecreatefromgif($source_file); + break; + // jpg + case 'jpeg' : + case 'jpg' : + $source = imagecreatefromjpeg($source_file); + break; + // png + case 'png' : + $source = imagecreatefrompng($source_file); + break; + // bmp + case 'wbmp' : + case 'bmp' : + $source = imagecreatefromwbmp($source_file); + break; + default : + return; + } + + if(!$source) return; + + // 디렉토리 생성 + $path = preg_replace('/\/([^\.^\/]*)\.(gif|png|jpeg|bmp|wbmp)$/i','',$target_file); + FileHandler::makeDir($path); + + if($new_width != $width || $new_height != $height) { + if(function_exists('imagecopyresampled')) imagecopyresampled($thumb, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height); + else imagecopyresized($thumb, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height); + } else $thumb = $source; + + // 파일을 쓰고 끝냄 + switch($target_type) { + case 'gif' : + imagegif($thumb, $target_file, 100); + break; + case 'jpeg' : + case 'jpg' : + imagejpeg($thumb, $target_file, 100); + break; + case 'png' : + imagepng($thumb, $target_file, 100); + break; + case 'wbmp' : + case 'bmp' : + imagewbmp($thumb, $target_file, 100); + break; + } + @unlink($source_file); + } } ?> diff --git a/common/js/common.js b/common/js/common.js index 5db53fc04..89b853071 100644 --- a/common/js/common.js +++ b/common/js/common.js @@ -8,10 +8,9 @@ * @brief location.href에서 특정 key의 값을 return **/ String.prototype.getQuery = function(key) { - var href = location.href; - var idx = href.indexOf('?'); + var idx = this.indexOf('?'); if(idx == -1) return; - var query_string = href.substr(idx+1, href.length); + var query_string = this.substr(idx+1, this.length); var args = {} query_string.replace(/([^=]+)=([^&]*)(&|$)/g, function() { args[arguments[1]] = arguments[2]; }); @@ -24,12 +23,11 @@ String.prototype.getQuery = function(key) { * @brief location.href에서 특정 key의 값을 return **/ String.prototype.setQuery = function(key, val) { - var href = location.href; - var idx = href.indexOf('?'); - var uri = href; + var idx = this.indexOf('?'); + var uri = this; if(idx != -1) { - uri = href.substr(0, idx); - var query_string = href.substr(idx+1, href.length); + uri = this.substr(0, idx); + var query_string = this.substr(idx+1, this.length); var args = {} query_string.replace(/([^=]+)=([^&]*)(&|$)/g, function() { args[arguments[1]] = arguments[2]; }); args[key] = val; diff --git a/modules/member/member.controller.php b/modules/member/member.controller.php index fde0861b4..09146662f 100644 --- a/modules/member/member.controller.php +++ b/modules/member/member.controller.php @@ -303,49 +303,12 @@ // 정해진 사이즈를 구함 $max_width = $config->image_name_max_width; - if(!$max_width) $max_width = "80"; + if(!$max_width) $max_width = "90"; $max_height = $config->image_name_max_height; if(!$max_height) $max_height = "20"; - - // 이미지 정보를 구함 - list($width, $height, $type, $attrs) = getimagesize($file['tmp_name']); - // 이미지 정보가 정해진 크기보다 크면 크기를 바꿈 - if($width>$max_width) $new_width = $max_width; - else $new_width = $width; - if($height>$max_height) $new_height = $max_height; - else $new_height = $height; - - // 업로드한 파일을 옮기지 않고 gd를 이용해서 gif 이미지를 만듬 (gif, jpg, png, bmp가 아니면 역시 무시) - $thumb = imagecreatetruecolor($new_width, $new_height); - switch($type) { - // gif - case 1 : - $source = imagecreatefromgif($file['tmp_name']); - break; - // jpg - case 2 : - $source = imagecreatefromjpeg($file['tmp_name']); - break; - // png - case 3 : - $source = imagecreatefrompng($file['tmp_name']); - break; - // bmp - case 6 : - $source = imagecreatefromwbmp($file['tmp_name']); - break; - } - - if(!$source) return $this->stop('msg_not_uploaded_image_name'); - - if(function_exists('imagecopyresampled')) imagecopyresampled($thumb, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height); - else imagecopyresized($thumb, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height); - - // 파일을 쓰고 끝냄 $target_filename = sprintf('files/attach/image_name/%s%d.gif', getNumberingPath($member_srl), $member_srl); - imagegif($thumb, $target_filename, 100); - @unlink($file['tmp_name']); + FileHandler::createImageFile($file['tmp_name'], $target_filename, $max_width, $max_height, 'gif'); // 페이지 리프레쉬 $this->setRefreshPage(); @@ -393,48 +356,12 @@ // 정해진 사이즈를 구함 $max_width = $config->image_mark_max_width; - if(!$max_width) $max_width = "80"; + if(!$max_width) $max_width = "20"; $max_height = $config->image_mark_max_height; if(!$max_height) $max_height = "20"; - // 이미지 정보를 구함 - list($width, $height, $type, $attrs) = getimagesize($file['tmp_name']); - - // 이미지 정보가 정해진 크기보다 크면 크기를 바꿈 - if($width>$max_width) $new_width = $max_width; - else $new_width = $width; - if($height>$max_height) $new_height = $max_height; - else $new_height = $height; - - // 업로드한 파일을 옮기지 않고 gd를 이용해서 gif 이미지를 만듬 (gif, jpg, png, bmp가 아니면 역시 무시) - $thumb = imagecreatetruecolor($new_width, $new_height); - switch($type) { - // gif - case 1 : - $source = imagecreatefromgif($file['tmp_name']); - break; - // jpg - case 2 : - $source = imagecreatefromjpeg($file['tmp_name']); - break; - // png - case 3 : - $source = imagecreatefrompng($file['tmp_name']); - break; - // bmp - case 6 : - $source = imagecreatefromwbmp($file['tmp_name']); - break; - } - - if(!$source) return $this->stop('msg_not_uploaded_image_mark'); - - if(function_exists('imagecopyresampled')) imagecopyresampled($thumb, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height); - else imagecopyresized($thumb, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height); - - // 파일을 쓰고 끝냄 $target_filename = sprintf('files/attach/image_mark/%s%d.gif', getNumberingPath($member_srl), $member_srl); - imagegif($thumb, $target_filename, 100); + FileHandler::createImageFile($file['tmp_name'], $target_filename, $max_width, $max_height, 'gif'); // 페이지 리프레쉬 $this->setRefreshPage();