회원 이미지 자동으로 조절하여 올려지는 방법 정보
회원 이미지 자동으로 조절하여 올려지는 방법본문
http://www.showyourlove.co.kr/
위에 사이트 같은경우 가입하고 회원사진을 올릴때
50x50 픽셀이라고 하지만 아무거나 올려도 자동으로 등록이 되는데요.
이미지를 올릴때 사이즈를 조절해서 올려야하는 불편함이 있습니다.
자동으로 조절하는 소스좀 알려주시면 감사드리겠습니다~~~ ^^
위에 사이트 같은경우 가입하고 회원사진을 올릴때
50x50 픽셀이라고 하지만 아무거나 올려도 자동으로 등록이 되는데요.
이미지를 올릴때 사이즈를 조절해서 올려야하는 불편함이 있습니다.
자동으로 조절하는 소스좀 알려주시면 감사드리겠습니다~~~ ^^
댓글 전체
썸네일생성을 이용하시면 됩니다
스킨자료에서 갤러리형 소스를 응용해보세요~
<?
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
if (!function_exists("makeThumbs")) {
function makeThumbs($oriPath, $oriFileName, $thmWidth="", $thmHeight="", $thmAlt="") {
global $g4, $board_skin_path;
$orgWidth = $thmWidth;
$orgHeight = $thmHeight;
$errorFilePrt = "<img src='$board_skin_path/img/noimage.gif' border=0 title='이미지 없음'>";
$oriFile = $oriPath . "/" . $oriFileName;
if (is_file($oriFile) == false) return 1; // 원본 부재
$thmPath = $oriPath . "/thumbs";
$thmFile = $thmPath . "/" . $oriFileName;
$oriSize = getimagesize($oriFile);
$oriWidth = $oriSize[0];
$oriHeight = $oriSize[1];
$oriType = $oriSize[2];
if ($oriType > 3) return 2; // 원본 이미지 타입 오류
$oriRate = $oriWidth / $oriHeight;
if ($thmWidth == "" && $thmHeight == "") return $errorFilePrt; // 썸네일 사이즈 미지정
if ($thmWidth == "") $thmWidth = $thmHeight * $oriRate;
if ($thmHeight == "") $thmHeight = $thmWidth / $oriRate;
$widthRate = $thmWidth / $oriWidth;
$heightRate = $thmHeight / $oriHeight;
$oriFilePrt = "<img src=\"{$oriFile}\" width=\"{$oriWidth}\" height=\"{$oriHeight}\" border=\"0\" alt=\"{$thmAlt}\" />";
if ($widthRate >= 1 && $heightRate >= 1) { // 리사이징 불필요
return $oriFilePrt;
}
if (file_exists($thmFile)) { // 썸네일 유무
$fp = fopen($thmFile, "r");
$fstat = fstat($fp);
$thmFileTime = $fstat['ctime'];
fclose($fp);
$fp = fopen($oriFile, "r");
$fstat = fstat($fp);
$oriFileTime = $fstat['ctime'];
fclose($fp);
if ($thmFileTime > $oriFileTime) { // 썸네일 갱신 불필요
$thmSize = getimagesize($thmFile);
$thmFilePrt = "<img src=\"{$thmFile}\" width=\"{$thmSize[0]}\" height=\"{$thmSize[1]}\" border=\"0\" alt=\"{$thmAlt}\" />";
} else {
@unlink($thmFile);
}
}
@mkdir($thmPath);
@chmod($thmPath, 0707);
if ($widthRate < $heightRate) {
$tempWidth = (int)($oriWidth * $heightRate);
$tempHeight = $thmHeight;
} else {
$tempWidth = $thmWidth;
$tempHeight = (int)($oriHeight * $widthRate);
}
$thmHeight = (int)($oriHeight * $widthRate);
if($tempHeight > $orgHeight){
$thmHeight = $orgHeight;
$thmWidth = ceil( $thmWidth * $orgHeight/$tempHeight );
$tempWidth = $thmWidth;
$tempHeight = $thmHeight;
}
if($tempWidth > $orgWidth){
$thmWidth = $orgWidth;
//$thmHeight = ceil( $thmHeight * $orgWidth/$tempWidth );
$tempWidth = $thmWidth;
$tempHeight = $thmHeight;
}
//echo " $thmWidth, $thmHeight "; exit;
if ($tempWidth == "") $tempWidth = $thmWidth;
if ($tempHeight == "") $tempHeight = $thmHeight;
switch($oriType) {
case(1) :
if(function_exists('imagecreateFromGif')) $tempImage = imagecreateFromGif($oriFile);
break;
case(2) :
if(function_exists('imagecreateFromJpeg')) $tempImage = imagecreateFromJpeg($oriFile);
break;
case(3) :
if(function_exists('imagecreateFromPng')) $tempImage = imagecreateFromPng($oriFile);
break;
}
if ($tempImage) {
if (function_exists('imagecreatetruecolor')) {
$tempCanvas = imagecreatetruecolor($thmWidth, $thmHeight);
} else {
$tempCanvas = imagecreate($thmWidth, $thmHeight);
}
if (function_exists('imagecopyresampled')) {
imagecopyresampled($tempCanvas, $tempImage, 0, 0, 0, 0, $tempWidth, $tempHeight, ImageSX($tempImage), ImageSY($tempImage));
} else {
imagecopyresized($tempCanvas, $tempImage, 0, 0, 0, 0, $tempWidth, $tempHeight, ImageSX($tempImage), ImageSY($tempImage));
}
ImageDestroy($tempImage);
ImageJpeg($tempCanvas, $thmFile, 100);
ImageDestroy($tempCanvas);
unset($tempImage, $tempCanvas);
}
//{$thmWidth}x{$thmHeight} {$tempWidth}x{$tempHeight}
$thmFilePrt = "<img src=\"{$thmFile}\" width=\"{$thmWidth}\" border=\"0\" alt=\"{$thmAlt}\" />";
return $thmFilePrt;
}
}
?>
스킨자료에서 갤러리형 소스를 응용해보세요~
<?
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
if (!function_exists("makeThumbs")) {
function makeThumbs($oriPath, $oriFileName, $thmWidth="", $thmHeight="", $thmAlt="") {
global $g4, $board_skin_path;
$orgWidth = $thmWidth;
$orgHeight = $thmHeight;
$errorFilePrt = "<img src='$board_skin_path/img/noimage.gif' border=0 title='이미지 없음'>";
$oriFile = $oriPath . "/" . $oriFileName;
if (is_file($oriFile) == false) return 1; // 원본 부재
$thmPath = $oriPath . "/thumbs";
$thmFile = $thmPath . "/" . $oriFileName;
$oriSize = getimagesize($oriFile);
$oriWidth = $oriSize[0];
$oriHeight = $oriSize[1];
$oriType = $oriSize[2];
if ($oriType > 3) return 2; // 원본 이미지 타입 오류
$oriRate = $oriWidth / $oriHeight;
if ($thmWidth == "" && $thmHeight == "") return $errorFilePrt; // 썸네일 사이즈 미지정
if ($thmWidth == "") $thmWidth = $thmHeight * $oriRate;
if ($thmHeight == "") $thmHeight = $thmWidth / $oriRate;
$widthRate = $thmWidth / $oriWidth;
$heightRate = $thmHeight / $oriHeight;
$oriFilePrt = "<img src=\"{$oriFile}\" width=\"{$oriWidth}\" height=\"{$oriHeight}\" border=\"0\" alt=\"{$thmAlt}\" />";
if ($widthRate >= 1 && $heightRate >= 1) { // 리사이징 불필요
return $oriFilePrt;
}
if (file_exists($thmFile)) { // 썸네일 유무
$fp = fopen($thmFile, "r");
$fstat = fstat($fp);
$thmFileTime = $fstat['ctime'];
fclose($fp);
$fp = fopen($oriFile, "r");
$fstat = fstat($fp);
$oriFileTime = $fstat['ctime'];
fclose($fp);
if ($thmFileTime > $oriFileTime) { // 썸네일 갱신 불필요
$thmSize = getimagesize($thmFile);
$thmFilePrt = "<img src=\"{$thmFile}\" width=\"{$thmSize[0]}\" height=\"{$thmSize[1]}\" border=\"0\" alt=\"{$thmAlt}\" />";
} else {
@unlink($thmFile);
}
}
@mkdir($thmPath);
@chmod($thmPath, 0707);
if ($widthRate < $heightRate) {
$tempWidth = (int)($oriWidth * $heightRate);
$tempHeight = $thmHeight;
} else {
$tempWidth = $thmWidth;
$tempHeight = (int)($oriHeight * $widthRate);
}
$thmHeight = (int)($oriHeight * $widthRate);
if($tempHeight > $orgHeight){
$thmHeight = $orgHeight;
$thmWidth = ceil( $thmWidth * $orgHeight/$tempHeight );
$tempWidth = $thmWidth;
$tempHeight = $thmHeight;
}
if($tempWidth > $orgWidth){
$thmWidth = $orgWidth;
//$thmHeight = ceil( $thmHeight * $orgWidth/$tempWidth );
$tempWidth = $thmWidth;
$tempHeight = $thmHeight;
}
//echo " $thmWidth, $thmHeight "; exit;
if ($tempWidth == "") $tempWidth = $thmWidth;
if ($tempHeight == "") $tempHeight = $thmHeight;
switch($oriType) {
case(1) :
if(function_exists('imagecreateFromGif')) $tempImage = imagecreateFromGif($oriFile);
break;
case(2) :
if(function_exists('imagecreateFromJpeg')) $tempImage = imagecreateFromJpeg($oriFile);
break;
case(3) :
if(function_exists('imagecreateFromPng')) $tempImage = imagecreateFromPng($oriFile);
break;
}
if ($tempImage) {
if (function_exists('imagecreatetruecolor')) {
$tempCanvas = imagecreatetruecolor($thmWidth, $thmHeight);
} else {
$tempCanvas = imagecreate($thmWidth, $thmHeight);
}
if (function_exists('imagecopyresampled')) {
imagecopyresampled($tempCanvas, $tempImage, 0, 0, 0, 0, $tempWidth, $tempHeight, ImageSX($tempImage), ImageSY($tempImage));
} else {
imagecopyresized($tempCanvas, $tempImage, 0, 0, 0, 0, $tempWidth, $tempHeight, ImageSX($tempImage), ImageSY($tempImage));
}
ImageDestroy($tempImage);
ImageJpeg($tempCanvas, $thmFile, 100);
ImageDestroy($tempCanvas);
unset($tempImage, $tempCanvas);
}
//{$thmWidth}x{$thmHeight} {$tempWidth}x{$tempHeight}
$thmFilePrt = "<img src=\"{$thmFile}\" width=\"{$thmWidth}\" border=\"0\" alt=\"{$thmAlt}\" />";
return $thmFilePrt;
}
}
?>
헉, 감사합니다. 그런데 이걸 어디에 넣어야 되나요?