어디서 주워온 함수인데요...
적용시켰는데 잘 되서 쓸려구 하는데 페이지 불러올대마다 재 생성 하는것같습니다.
좀 도와주세요;;
////////////////////////////////////
<?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__) 등을 활용해서 이 문제를 해결하고 있습니다.
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7130 | 11년 전 | 2304 | ||
| 7129 | 11년 전 | 710 | ||
| 7128 |
senseme
|
11년 전 | 1299 | |
| 7127 | 11년 전 | 1173 | ||
| 7126 | 11년 전 | 824 | ||
| 7125 | 11년 전 | 2952 | ||
| 7124 | 11년 전 | 1428 | ||
| 7123 |
잘살아보자
|
11년 전 | 1291 | |
| 7122 |
잘살아보자
|
11년 전 | 689 | |
| 7121 |
잘살아보자
|
11년 전 | 3050 | |
| 7120 |
잘살아보자
|
11년 전 | 2918 | |
| 7119 |
잘살아보자
|
11년 전 | 732 | |
| 7118 |
잘살아보자
|
11년 전 | 3433 | |
| 7117 |
잘살아보자
|
11년 전 | 853 | |
| 7116 | 11년 전 | 746 | ||
| 7115 | 11년 전 | 1032 | ||
| 7114 | 11년 전 | 851 | ||
| 7113 | 11년 전 | 665 | ||
| 7112 | 11년 전 | 1086 | ||
| 7111 | 11년 전 | 1800 | ||
| 7110 | 11년 전 | 1035 | ||
| 7109 |
버섯먹은나
|
11년 전 | 813 | |
| 7108 | 11년 전 | 648 | ||
| 7107 | 11년 전 | 2412 | ||
| 7106 | 11년 전 | 1961 | ||
| 7105 | 11년 전 | 2485 | ||
| 7104 | 11년 전 | 1425 | ||
| 7103 |
|
11년 전 | 2711 | |
| 7102 | 11년 전 | 3119 | ||
| 7101 | 11년 전 | 4446 | ||
| 7100 | 11년 전 | 5794 | ||
| 7099 | 11년 전 | 2143 | ||
| 7098 | 11년 전 | 1726 | ||
| 7097 | 11년 전 | 1463 | ||
| 7096 | 11년 전 | 1129 | ||
| 7095 |
잘살아보자
|
11년 전 | 859 | |
| 7094 |
잘살아보자
|
11년 전 | 1063 | |
| 7093 |
잘살아보자
|
11년 전 | 940 | |
| 7092 |
잘살아보자
|
11년 전 | 1411 | |
| 7091 |
잘살아보자
|
11년 전 | 2212 | |
| 7090 |
잘살아보자
|
11년 전 | 895 | |
| 7089 | 11년 전 | 1068 | ||
| 7088 | 11년 전 | 1715 | ||
| 7087 | 11년 전 | 1411 | ||
| 7086 | 11년 전 | 1314 | ||
| 7085 |
|
11년 전 | 1238 | |
| 7084 | 11년 전 | 1157 | ||
| 7083 | 11년 전 | 3505 | ||
| 7082 | 11년 전 | 1154 | ||
| 7081 | 11년 전 | 1738 | ||
| 7080 | 11년 전 | 2025 | ||
| 7079 | 11년 전 | 1333 | ||
| 7078 | 11년 전 | 1305 | ||
| 7077 | 11년 전 | 1314 | ||
| 7076 | 11년 전 | 771 | ||
| 7075 | 11년 전 | 1155 | ||
| 7074 |
네이비칼라
|
11년 전 | 1509 | |
| 7073 | 11년 전 | 1479 | ||
| 7072 |
|
11년 전 | 836 | |
| 7071 | 11년 전 | 1211 | ||
| 7070 | 11년 전 | 935 | ||
| 7069 | 11년 전 | 1709 | ||
| 7068 | 11년 전 | 1366 | ||
| 7067 |
TPSint
|
11년 전 | 749 | |
| 7066 | 11년 전 | 2154 | ||
| 7065 | 11년 전 | 6653 | ||
| 7064 | 11년 전 | 1296 | ||
| 7063 | 11년 전 | 1141 | ||
| 7062 | 11년 전 | 1080 | ||
| 7061 | 11년 전 | 919 | ||
| 7060 | 11년 전 | 1475 | ||
| 7059 | 11년 전 | 886 | ||
| 7058 |
EngineMan
|
11년 전 | 3407 | |
| 7057 | 11년 전 | 1251 | ||
| 7056 | 11년 전 | 1641 | ||
| 7055 | 11년 전 | 1020 | ||
| 7054 | 11년 전 | 2659 | ||
| 7053 |
네이비칼라
|
11년 전 | 1289 | |
| 7052 | 11년 전 | 2584 | ||
| 7051 | 11년 전 | 1941 | ||
| 7050 | 11년 전 | 2457 | ||
| 7049 | 11년 전 | 1413 | ||
| 7048 | 11년 전 | 2540 | ||
| 7047 | 11년 전 | 1362 | ||
| 7046 | 11년 전 | 1042 | ||
| 7045 | 11년 전 | 1069 | ||
| 7044 | 11년 전 | 5441 | ||
| 7043 | 11년 전 | 1234 | ||
| 7042 | 11년 전 | 793 | ||
| 7041 |
열라뽕똬이
|
11년 전 | 763 | |
| 7040 | 11년 전 | 1118 | ||
| 7039 | 11년 전 | 1469 | ||
| 7038 | 11년 전 | 1879 | ||
| 7037 | 11년 전 | 2182 | ||
| 7036 | 11년 전 | 1089 | ||
| 7035 | 11년 전 | 1410 | ||
| 7034 | 11년 전 | 1360 | ||
| 7033 |
열라뽕똬이
|
11년 전 | 1000 | |
| 7032 | 11년 전 | 756 | ||
| 7031 | 11년 전 | 2188 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기