|
 |
15년 전 |
// 썸네일화 만들기 가로 370 짜리 메인 이미지 만들기
$dst_img = thumbnail ($$temp_cf,"370","");
make_imagefile ($dst_img,"$file_dir/1_$file_base","100");
################################################################################
// 이미지로드
################################################################################
function LoadImage ($fName) {
$file_ext = strtolower(substr(strrchr($fName,"."), 1));
switch ($file_ext) {
case "jpg": case "jpeg":
$img = @ImageCreateFromJPEG ($fName);
break;
case "gif":
$img = @ImageCreateFromGIF ($fName);
break;
case "png":
$img = @ImageCreateFromPNG ($fName);
break;
}
if (!$img) {
$img = ImageCreate (150, 30);
$bgc = ImageColorAllocate ($img, 255, 255, 255);
$tc = ImageColorAllocate ($img, 0, 0, 0);
ImageFilledRectangle ($img, 0, 0, 150, 30, $bgc);
ImageString ($img, 1, 5, 5, "Error loading $fName", $tc);
}
return $img;
}
################################################################################
// 이미지 썸네일 만들기
################################################################################
function thumbnail ($filepath,$width="",$height="") {
$size=getimagesize($filepath); //원본 이미지사이즈를 구함
if(!$height) {
$height=($size[1]*$width)/$size[0];
if($size[0] < $width) {
$width = $size[0];
$height = $size[1];
}
}
if(!$width) {
$width=($size[0]*$height)/$size[1];
if($size[1] < $height) {
$width = $size[0];
$height = $size[1];
}
}
$shr_rateX = $width / $size[0];
$shr_rateY = $height / $size[1];
$base = ($shr_rateX <= $shr_rateY) ? "y" : "x";
$src_im=LoadImage($filepath);
if($base == "y") {
$new_width=round(($size[0] * $height)/$size[1]); // (가로크기 * 새로운 세로 크기) / 세로크기
$offsetX = round(($new_width - $width) / 2); //각각 좌우로 잘라낼 길이
$offsetY = 0;
}
if($base == "x") {
$size=getimagesize($filepath); //원본 이미지 사이즈 구함
$new_height=round(($size[1] * $width)/$size[0]); // (세로크기 * 새로운 가로크기) / 가로크기
$offsetX = 0;
$offsetY = round(($new_height - $height) / 2); // 각각 상하로 잘라낼 길이
}
//$dst_img=ImageCreate($width,$height); //결과물 이미지 생성
$dst_img=ImageCreateTrueColor($width,$height); //결과물 이미지 생성
imagecopyresampled($dst_img,$src_im,0,0,$offsetX,$offsetY,$width,$height,ImageSX($src_im)-$offsetX,ImageSY($src_im)-$offsetY); //만들기
//ImageCopyResized($dst_img,$src_im,0,0,$offsetX,$offsetY,$width,$height,ImageSX($src_im)-$offsetX,ImageSY($src_im)-$offsetY); //만들기
return $dst_img;
}
################################################################################
// 이미지생성
################################################################################
function make_imagefile ($dst_img,$filename,$quality="100") {
$file_ext = strtolower(substr(strrchr($filename,"."), 1));
//if(eregi("bmp", $file_ext)) {
// error_msg("지원하지 않는 파일형식입니다. 다시 시도해 주십시오.\\n\\n$file_ext 파일 형식 은 지원 하지 않습니다.");
// exit;
//}
if($file_ext == "jpg") ImageJPEG($dst_img, $filename, $quality);
elseif($file_ext == "gif") ImageGIF($dst_img, $filename);
elseif($file_ext == "png") ImagePNG($dst_img, $filename);
ImageDestroy($dst_img);
return 1;
} |
|
추천 : 969 |
추천
목록
|
|