어디서 주워온 함수인데요...
적용시켰는데 잘 되서 쓸려구 하는데 페이지 불러올대마다 재 생성 하는것같습니다.
좀 도와주세요;;
////////////////////////////////////
<?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>");
}
//////////////////////////////
이렇게 했습니다.
이거 적용하는데 일주일 걸렸습니다 ,, 제발 좀 도와주세요 ㅠㅠ
적용시켰는데 잘 되서 쓸려구 하는데 페이지 불러올대마다 재 생성 하는것같습니다.
좀 도와주세요;;
////////////////////////////////////
<?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개
17년 전
출력부분에
$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 = "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>");
눈치껏 해봤는데 이건 틀린듯한데 어떻게 해야하나요?
17년 전
댓글로 작성하신 걸 기준으로 말씀드리면...
$thumb는 HTTP로 접근할 때의 경로가 됩니다. 즉, file_exists로는 검사할 수가 없죠.
file_exists("/home/mysite/www/" + $thumb) 같은 식으로 절대 경로를 앞에 추가하면 어떨까요?
$thumb는 HTTP로 접근할 때의 경로가 됩니다. 즉, file_exists로는 검사할 수가 없죠.
file_exists("/home/mysite/www/" + $thumb) 같은 식으로 절대 경로를 앞에 추가하면 어떨까요?
17년 전
P.S.
많은 PHP 프로그램들이 절대 경로를 넣은 변수 또는 define을 사용하거나,
dirname(__FILE__) 등을 활용해서 이 문제를 해결하고 있습니다.
많은 PHP 프로그램들이 절대 경로를 넣은 변수 또는 define을 사용하거나,
dirname(__FILE__) 등을 활용해서 이 문제를 해결하고 있습니다.
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7630 | 10년 전 | 635 | ||
| 7629 |
|
10년 전 | 2347 | |
| 7628 | 10년 전 | 768 | ||
| 7627 |
|
10년 전 | 1002 | |
| 7626 |
|
10년 전 | 1761 | |
| 7625 | 10년 전 | 661 | ||
| 7624 | 10년 전 | 684 | ||
| 7623 |
|
10년 전 | 3011 | |
| 7622 | 10년 전 | 698 | ||
| 7621 |
leeleeleelee
|
10년 전 | 569 | |
| 7620 | 10년 전 | 528 | ||
| 7619 | 10년 전 | 458 | ||
| 7618 | 10년 전 | 999 | ||
| 7617 | 10년 전 | 713 | ||
| 7616 | 10년 전 | 614 | ||
| 7615 | 10년 전 | 711 | ||
| 7614 | 10년 전 | 1214 | ||
| 7613 |
|
10년 전 | 2054 | |
| 7612 | 10년 전 | 1124 | ||
| 7611 | 10년 전 | 1385 | ||
| 7610 |
|
10년 전 | 1875 | |
| 7609 |
|
10년 전 | 1291 | |
| 7608 |
mwdkim
|
10년 전 | 1097 | |
| 7607 |
|
10년 전 | 1023 | |
| 7606 |
mwdkim
|
10년 전 | 3903 | |
| 7605 | 10년 전 | 669 | ||
| 7604 | 10년 전 | 1005 | ||
| 7603 | 10년 전 | 1631 | ||
| 7602 |
|
10년 전 | 1041 | |
| 7601 |
AniNest
|
10년 전 | 2763 | |
| 7600 |
port443
|
10년 전 | 1001 | |
| 7599 | 10년 전 | 924 | ||
| 7598 | 10년 전 | 991 | ||
| 7597 | 10년 전 | 4553 | ||
| 7596 |
SeungYeon
|
10년 전 | 868 | |
| 7595 |
untitled
|
10년 전 | 2395 | |
| 7594 |
프로그래머7
|
10년 전 | 1700 | |
| 7593 |
untitled
|
10년 전 | 2337 | |
| 7592 |
untitled
|
10년 전 | 1916 | |
| 7591 |
untitled
|
10년 전 | 2653 | |
| 7590 |
아리마2001
|
10년 전 | 823 | |
| 7589 | 10년 전 | 1083 | ||
| 7588 |
|
10년 전 | 2902 | |
| 7587 | 10년 전 | 1279 | ||
| 7586 | 10년 전 | 643 | ||
| 7585 | 10년 전 | 1662 | ||
| 7584 | 10년 전 | 1396 | ||
| 7583 |
leeleeleelee
|
10년 전 | 1139 | |
| 7582 |
|
10년 전 | 1074 | |
| 7581 | 10년 전 | 1305 | ||
| 7580 | 10년 전 | 947 | ||
| 7579 |
|
10년 전 | 586 | |
| 7578 | 10년 전 | 1398 | ||
| 7577 |
|
10년 전 | 1853 | |
| 7576 | 10년 전 | 1368 | ||
| 7575 |
멋진남자임
|
10년 전 | 1447 | |
| 7574 | 10년 전 | 2089 | ||
| 7573 | 10년 전 | 3220 | ||
| 7572 | 10년 전 | 749 | ||
| 7571 |
|
10년 전 | 772 | |
| 7570 |
|
10년 전 | 1295 | |
| 7569 | 10년 전 | 1524 | ||
| 7568 |
this1mg
|
10년 전 | 1023 | |
| 7567 |
|
10년 전 | 733 | |
| 7566 | 10년 전 | 902 | ||
| 7565 |
Angel하늘
|
10년 전 | 966 | |
| 7564 |
seoldi
|
10년 전 | 1208 | |
| 7563 |
|
10년 전 | 1353 | |
| 7562 |
멋진남자임
|
10년 전 | 2047 | |
| 7561 | 10년 전 | 684 | ||
| 7560 |
leeleeleelee
|
10년 전 | 883 | |
| 7559 | 10년 전 | 5014 | ||
| 7558 |
RinaP
|
10년 전 | 755 | |
| 7557 |
|
10년 전 | 1222 | |
| 7556 | 10년 전 | 1172 | ||
| 7555 |
hyohyojj1234
|
10년 전 | 1637 | |
| 7554 | 10년 전 | 1076 | ||
| 7553 |
senseme
|
10년 전 | 1322 | |
| 7552 |
ehdltdoit
|
10년 전 | 1419 | |
| 7551 |
|
10년 전 | 1803 | |
| 7550 |
leeleeleelee
|
10년 전 | 1566 | |
| 7549 | 10년 전 | 2396 | ||
| 7548 | 10년 전 | 1816 | ||
| 7547 |
멋진남자임
|
10년 전 | 1930 | |
| 7546 | 10년 전 | 970 | ||
| 7545 |
ILMare1003
|
10년 전 | 1258 | |
| 7544 |
|
10년 전 | 1211 | |
| 7543 | 10년 전 | 866 | ||
| 7542 | 10년 전 | 637 | ||
| 7541 |
울라라라우
|
10년 전 | 850 | |
| 7540 | 10년 전 | 1584 | ||
| 7539 | 10년 전 | 904 | ||
| 7538 |
|
10년 전 | 1816 | |
| 7537 | 10년 전 | 3592 | ||
| 7536 |
Gaumi
|
10년 전 | 1389 | |
| 7535 |
프로그램은어려워
|
10년 전 | 1247 | |
| 7534 |
senseme
|
10년 전 | 1195 | |
| 7533 | 10년 전 | 1172 | ||
| 7532 | 10년 전 | 836 | ||
| 7531 | 10년 전 | 2029 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기