|
Server : Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 DAV/2 PHP/5.2.17 System : Linux localhost 2.6.18-419.el5 #1 SMP Fri Feb 24 22:47:42 UTC 2017 x86_64 User : nobody ( 99) PHP Version : 5.2.17 Disable Function : NONE Directory : /home/queenjbs/www/gallary/ |
Upload File : |
<?
/**
* $max_side ¿øÇϽô »çÀÌÁ ³ÖÀ¸½Ã¸é ±ä ÂÊÀ» °Å±â¿¡ ¸ÂÃß¾î ¼¶³×ÀÏÀ» »ý¼ºÇÑ´Ù.
* $fixed = true À϶§´Â ¹«Á¶°Ç 4:3 À̳ª 3:4·Î ¸ÂÃß¾î »ý¼ºÇÑ´Ù. falseÀ̸é
* ±æÀÌ¿¡ ºñ·ÊÇÏ´Â ¼¶³×ÀÏÀ» »ý¼ºÇÑ´Ù.
* $file ¿øº» ÆÄÀÏÀÌ ÀÖ´Â °æ·Î¸¦ ÁöÁ¤ÇÑ´Ù.
* ¿¹: "upload/pic/pic1.gif"
* @return ¼¶³×ÀÏ °æ·Î
*/
class thumb {
public function __construct() {}
// create thumbnail, will accept jpeg and gif.
public static function create_thumbnail($file, $max_side = false, $fixed = false) {
// 1 = GIF, 2 = JPEG
if(!$max_side) $max_side = 100;
if(file_exists($file)) {
$type = getimagesize($file);
if(!function_exists('imagegif') && $type[2] == 1) {
$error = 'Filetype not supported. Thumbnail not created.';
}
elseif (!function_exists('imagejpeg') && $type[2] == 2) {
$error = 'Filetype not supported. Thumbnail not created.';
}
else {
// create the initial copy from the original file
if($type[2] == 1) {
$image = imagecreatefromgif($file);
}
elseif($type[2] == 2) {
$image = imagecreatefromjpeg($file);
}
if(function_exists('imageantialias'))
imageantialias($image, TRUE);
$image_attr = getimagesize($file);
// figure out the longest side
if($image_attr[0] > $image_attr[1]):
$image_width = $image_attr[0];
$image_height = $image_attr[1];
if($fixed) {
$image_new_width = $max_side;
$image_new_height = (int)($max_side * 3 / 4);
// 4:3 ratio
} else {
$image_new_width = $max_side;
$image_ratio = $image_width / $image_new_width;
$image_new_height = (int) ($image_height / $image_ratio);
}
//width > height
else:
$image_width = $image_attr[0];
$image_height = $image_attr[1];
if($fixed) {
$image_new_height = $max_side;
$image_new_width = (int)($max_side * 3 / 4);
// 3:4 ratio
} else {
$image_new_height = $max_side;
$image_ratio = $image_height / $image_new_height;
$image_new_width = (int) ($image_width / $image_ratio);
}
//height > width
endif;
$thumbnail = imagecreatetruecolor($image_new_width, $image_new_height);
@ imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1]);
$thumb = preg_replace('!(\.[^.]+)?$!', '.thumbnail'.'$1', basename($file), 1);
$thumbpath = str_replace(basename($file), $thumb, $file);
// move the thumbnail to it's final destination
if($type[2] == 1) {
if (!imagegif($thumbnail, $thumbpath)) {
$error = 'Thumbnail path invalid';
}
}
elseif($type[2] == 2) {
if (!imagejpeg($thumbnail, $thumbpath)) {
$error = 'Thumbnail path invalid';
}
}
}
} else {
$error = 'File not found';
}
if(!empty($error)) {
die($error);
} else {
return $thumbpath;
}
}
};
$imagethumb = thumb::create_thumbnail("upload/pic/pic1.gif", 115);
// 115¿¡ ¸Â´Â ºñÀ²·Î Á¤È®È÷ ÁÙÀδÙ.
//$imagethumb = thumb::create_thumbnail("upload/pic/pic1.gif", 115, 1);
// 115·Î ÁÙÀÌÁö¸¸ 4:3 À̳ª 3:4ÀÌ´Ù.
?>