git-svn-id: http://xe-core.googlecode.com/svn/trunk@882 201d5d3c-b55e-5fd7-737f-ddc643e51545

This commit is contained in:
zero 2007-04-02 05:14:28 +00:00
parent ae77140c69
commit 4d6ad6b04d
3 changed files with 101 additions and 85 deletions

View file

@ -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);
}
}
?>

View file

@ -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;

View file

@ -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();