어디서 주워온 함수인데요...
적용시켰는데 잘 되서 쓸려구 하는데 페이지 불러올대마다 재 생성 하는것같습니다.
좀 도와주세요;;
////////////////////////////////////
<?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__) 등을 활용해서 이 문제를 해결하고 있습니다.
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 1930 | 17년 전 | 3001 | ||
| 1929 | 17년 전 | 1878 | ||
| 1928 | 17년 전 | 3989 | ||
| 1927 | 17년 전 | 1407 | ||
| 1926 |
지엔소프트
|
17년 전 | 1124 | |
| 1925 |
보드타는찌니
|
17년 전 | 1241 | |
| 1924 |
choijinhee
|
17년 전 | 1125 | |
| 1923 | 17년 전 | 1387 | ||
| 1922 | 17년 전 | 1743 | ||
| 1921 | 17년 전 | 2337 | ||
| 1920 | 17년 전 | 2414 | ||
| 1919 | 17년 전 | 1418 | ||
| 1918 | 17년 전 | 1168 | ||
| 1917 | 17년 전 | 2435 | ||
| 1916 | 17년 전 | 2866 | ||
| 1915 |
|
17년 전 | 3229 | |
| 1914 | 17년 전 | 3169 | ||
| 1913 | 17년 전 | 2338 | ||
| 1912 | 17년 전 | 3750 | ||
| 1911 | 17년 전 | 3179 | ||
| 1910 | 17년 전 | 5502 | ||
| 1909 | 17년 전 | 2655 | ||
| 1908 | 17년 전 | 1856 | ||
| 1907 | 17년 전 | 1933 | ||
| 1906 | 17년 전 | 1774 | ||
| 1905 | 17년 전 | 1706 | ||
| 1904 | 17년 전 | 2765 | ||
| 1903 | 17년 전 | 1890 | ||
| 1902 | 17년 전 | 1579 | ||
| 1901 | 17년 전 | 2067 | ||
| 1900 |
stuartkim
|
17년 전 | 1137 | |
| 1899 | 17년 전 | 1665 | ||
| 1898 | 17년 전 | 2882 | ||
| 1897 | 17년 전 | 2123 | ||
| 1896 | 17년 전 | 1820 | ||
| 1895 | 17년 전 | 2035 | ||
| 1894 | 17년 전 | 1319 | ||
| 1893 | 17년 전 | 1713 | ||
| 1892 | 17년 전 | 1214 | ||
| 1891 | 17년 전 | 1776 | ||
| 1890 | 17년 전 | 1803 | ||
| 1889 | 17년 전 | 1039 | ||
| 1888 | 17년 전 | 3136 | ||
| 1887 | 17년 전 | 4312 | ||
| 1886 | 17년 전 | 2462 | ||
| 1885 | 17년 전 | 7471 | ||
| 1884 | 17년 전 | 3833 | ||
| 1883 | 17년 전 | 4163 | ||
| 1882 | 17년 전 | 2424 | ||
| 1881 | 17년 전 | 2884 | ||
| 1880 | 17년 전 | 3634 | ||
| 1879 | 17년 전 | 4004 | ||
| 1878 | 17년 전 | 3165 | ||
| 1877 | 17년 전 | 3146 | ||
| 1876 | 17년 전 | 3293 | ||
| 1875 | 17년 전 | 2462 | ||
| 1874 | 17년 전 | 2057 | ||
| 1873 | 17년 전 | 3107 | ||
| 1872 | 17년 전 | 3255 | ||
| 1871 | 17년 전 | 4609 | ||
| 1870 | 17년 전 | 1589 | ||
| 1869 | 17년 전 | 2615 | ||
| 1868 | 17년 전 | 2689 | ||
| 1867 | 17년 전 | 1899 | ||
| 1866 | 17년 전 | 2220 | ||
| 1865 | 17년 전 | 1834 | ||
| 1864 | 17년 전 | 2371 | ||
| 1863 | 17년 전 | 3775 | ||
| 1862 | 17년 전 | 3894 | ||
| 1861 | 17년 전 | 2078 | ||
| 1860 | 17년 전 | 1358 | ||
| 1859 | 17년 전 | 1494 | ||
| 1858 |
|
17년 전 | 1646 | |
| 1857 | 17년 전 | 1631 | ||
| 1856 |
보드타는찌니
|
17년 전 | 1395 | |
| 1855 | 17년 전 | 1543 | ||
| 1854 |
|
17년 전 | 1358 | |
| 1853 | 17년 전 | 1846 | ||
| 1852 | 17년 전 | 2749 | ||
| 1851 | 17년 전 | 1846 | ||
| 1850 |
|
17년 전 | 1403 | |
| 1849 |
|
17년 전 | 1688 | |
| 1848 |
|
17년 전 | 2327 | |
| 1847 | 17년 전 | 1941 | ||
| 1846 |
은사시나무
|
17년 전 | 1263 | |
| 1845 |
갈색야생마
|
17년 전 | 5902 | |
| 1844 |
갈색야생마
|
17년 전 | 3281 | |
| 1843 |
갈색야생마
|
17년 전 | 3177 | |
| 1842 |
갈색야생마
|
17년 전 | 2589 | |
| 1841 |
갈색야생마
|
17년 전 | 2769 | |
| 1840 |
갈색야생마
|
17년 전 | 2718 | |
| 1839 |
갈색야생마
|
17년 전 | 3224 | |
| 1838 |
갈색야생마
|
17년 전 | 2353 | |
| 1837 |
갈색야생마
|
17년 전 | 2471 | |
| 1836 |
갈색야생마
|
17년 전 | 2532 | |
| 1835 |
갈색야생마
|
17년 전 | 2521 | |
| 1834 |
갈색야생마
|
17년 전 | 2663 | |
| 1833 |
갈색야생마
|
17년 전 | 3186 | |
| 1832 |
갈색야생마
|
17년 전 | 2699 | |
| 1831 |
갈색야생마
|
17년 전 | 1425 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기