k

썸네일 생성 함수인데요.. 페이지 불러올때마다 새로 만들어지는것 같은데;;

· 2008-07-31 (목) 19:47:51 · 2419 · 3
어디서 주워온 함수인데요...
적용시켰는데 잘 되서 쓸려구 하는데 페이지 불러올대마다 재 생성 하는것같습니다.

좀 도와주세요;;

////////////////////////////////////

<?php
class thumbnails {
function ResizeImage($image, $newimage, $newwidth=0, $newheight=0) {
if (!function_exists('ImageTypes'))
return false;
list($width,$height,$type) = GetImageSize($image);
if ($im = self::ReadImageFromFile($image, $type)) {
if ($newwidth==0)
$newwidth = ($newheight / $height) * $width;
else if ($newheight==0)
$newheight = ($newwidth / $width) * $height;
elseif ($newheight && ($width < $height))
$newwidth = ($newheight / $height) * $width;
else
$newheight = ($newwidth / $width) * $height;

if (function_exists('ImageCreateTrueColor'))
$im2 = ImageCreateTrueColor($newwidth,$newheight);
else
$im2 = ImageCreate($newwidth,$newheight);

if (function_exists('imagealphablending'))
imagealphablending($im2, false);
if (function_exists('imagesavealpha'))
imagesavealpha ($im2 , true);

if (function_exists('ImageCopyResampled'))
ImageCopyResampled($im2,$im,0,0,0,0,$newwidth,$newheight,$width,$height);
else
ImageCopyResized($im2,$im,0,0,0,0,$newwidth,$newheight,$width,$height);

if (self::WriteImageToFile($im2, $newimage, $type))
return true;
}
return false;
}
private function ReadImageFromFile($filename, $type) {
$imagetypes = ImageTypes();
switch ($type) {
case 1 :
if ($imagetypes & IMG_GIF)
return $im = ImageCreateFromGIF($filename);
break;
case 2 :
if ($imagetypes & IMG_JPEG)
return ImageCreateFromJPEG($filename);
break;
case 3 :
if ($imagetypes & IMG_PNG)
return ImageCreateFromPNG($filename);
break;
default:
return 0;
}
}
private function WriteImageToFile($im, $filename, $type) {
switch ($type) {
case 1 :
return ImageGIF($im, $filename);
case 2 :
return ImageJpeg($im, $filename, 85);
case 3 :
return ImagePNG($im, $filename);
default:
return false;
}
}

}


//thumbnails::ResizeImage("00_folder.jpg", "mini/test.jpg", 150)

?>


////////////////////

불러오는 리스트 페이지에

if ($row["image1"] != "") {
thumbnails::ResizeImage("uploads/images/$row[image1]", "uploads/images/mini/$row[image1]", 150);
print("<td width=10><IMG src=uploads/images/mini/$row[image1]></td>");
}

//////////////////////////////

이렇게 했습니다.

이거 적용하는데 일주일 걸렸습니다 ,, 제발 좀 도와주세요 ㅠㅠ
|

댓글 3개

2008-07-31 (목) 20:38:58
출력부분에

$thumb = "uploads/images/mini/$row[image1]";
// 썸네일 이미지가 존재하지 않는다면
if (!file_exists($thumb)) {
thumbnails::ResizeImage("uploads/images/$row[image1]", "uploads/images/mini/$row[image1]", 150);
}
else if (file_exists($thumb)) {
$img = "<img src='$thumb' height=54 border=0 style='border:1px solid #a1a1a1;margin-right:10px;'>";
}
else {
$img = "<img src='images/t.gif' border=0>";
}

print("<td width=10>$img</td>");

눈치껏 해봤는데 이건 틀린듯한데 어떻게 해야하나요?
댓글로 작성하신 걸 기준으로 말씀드리면...

$thumb는 HTTP로 접근할 때의 경로가 됩니다. 즉, file_exists로는 검사할 수가 없죠.

file_exists("/home/mysite/www/" + $thumb) 같은 식으로 절대 경로를 앞에 추가하면 어떨까요?
P.S.

많은 PHP 프로그램들이 절대 경로를 넣은 변수 또는 define을 사용하거나,

dirname(__FILE__) 등을 활용해서 이 문제를 해결하고 있습니다.
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

8,188건
+
제목 글쓴이 날짜 조회
11-08-16 조회 2,400
11-08-16 조회 2,379
11-08-12 조회 2,213
11-08-02 조회 2,795
11-07-27 조회 2,182
11-07-25 조회 2,313
11-06-28 조회 2,472
11-06-06 조회 3,976
11-06-04 조회 2,575
11-04-25 조회 6,159
11-04-22 조회 2,660
11-04-21 조회 2,875
11-04-08 조회 3,225
11-03-31 조회 2,805
11-03-20 조회 3,224
11-03-10 조회 2,849
11-03-04 조회 3,174
11-03-03 조회 2,899
11-02-26 조회 4,321
11-02-14 조회 5,675
11-02-08 조회 3,282
11-01-30 조회 5,370
11-01-14 조회 5,146
11-01-14 조회 3,719
11-01-14 조회 2,878
11-01-14 조회 2,915
11-01-14 조회 3,062
11-01-12 조회 2,803
11-01-07 조회 4,493
10-12-29 조회 2,427
10-12-22 조회 2,464
10-12-05 조회 5,812
10-11-22 조회 5,215
10-11-13 조회 3,586
10-10-27 조회 3,206
10-10-21 조회 2,902
10-09-21 조회 2,908
10-09-17 조회 2,948
10-09-15 조회 3,396
10-09-14 조회 4,005
10-05-18 조회 2,877
10-02-17 조회 4,310
10-02-12 조회 3,082
09-12-14 조회 5,111
09-12-14 조회 6,012
09-09-19 조회 4,378
09-08-16 조회 6,225
09-07-22 조회 5,630
09-04-13 조회 3,041
09-03-15 조회 5,045
09-03-05 조회 3,874
09-02-09 조회 2,820
08-12-30 조회 3,014
08-12-06 조회 3,216
08-11-30 조회 3,558
08-10-18 조회 4,394
08-10-08 조회 3,713
08-09-19 조회 4,338
08-09-05 조회 2,979
08-09-05 조회 5,086
08-09-05 조회 2,968
08-09-05 조회 3,561
08-09-05 조회 3,476
08-09-01 조회 4,494
08-08-07 조회 2,747
08-06-08 조회 3,218
08-06-02 조회 2,809
08-05-26 조회 5,234
08-05-09 조회 4,300
08-04-22 조회 3,889
08-04-17 조회 4,480
08-04-17 조회 5,558
08-04-17 조회 3,696
08-04-17 조회 8,677
08-04-17 조회 4,580
08-04-17 조회 4,491
08-04-09 조회 3,048
08-03-31 조회 3,545
08-03-26 조회 3,238
08-03-25 조회 3,530
08-03-25 조회 3,958
08-03-25 조회 4,004
08-03-25 조회 3,663
08-03-25 조회 3,555
08-03-25 조회 3,557
08-03-25 조회 5,245
08-02-03 조회 5,252
08-01-18 조회 6,615
08-01-17 조회 3,914
08-01-17 조회 3,734
08-01-12 조회 4,019
08-01-08 조회 3,349
07-12-28 조회 4,617
07-12-04 조회 3,489
07-11-30 조회 5,100
07-11-30 조회 5,715
07-11-02 조회 4,010
07-10-24 조회 3,987
07-10-24 조회 3,265
07-10-24 조회 3,371