function setFile($src = null) { $this->ext = strtolower(pathinfo($src, PATHINFO_EXTENSION)); if (is_file($src) && ($this->ext == "jpg" or $this->ext == "jpeg")) { $this->img_r = ImageCreateFromjpeg($src); } elseif (is_file($src) && $this->ext == "png") { $this->img_r = ImageCreateFrompng($src); } elseif (is_file($src) && $this->ext == "gif") { $this->img_r = ImageCreateFromgif($src); } $this->img_w = imagesx($this->img_r); $this->img_h = imagesy($this->img_r); }
private function createImageFromFile($file, $fileformat = 'jpg') { switch (strtolower($fileformat)) { case "jpg": case "jpeg": return ImageCreateFromJPEG($file); break; case "png": return ImageCreateFromPNG($file); break; case "wbmp": case "bmp": return imagecreatefromwbmp($file); break; case "gif": return ImageCreateFromgif($file); break; } return false; }
function setThumbnail($file, $upload_dir = ".", $thumbnail_upload_dir = "./thumb", $filename = "", $thumbnail_size = 250, $thumbnail_quality = 76, $limit_size = 2, $type = 1, $check = 0, $image_type = 0, $image_width = 800, $image_height = 600, $limit_length = 30) { if ($filename == "") { $filename = $file[name]; } $img_size = $this->setFileUpload($file, $upload_dir, $filename, $limit_size, $type, $check, $image_type, $image_width, $image_height = 600, $limit_length = 30); //앨범에서의 썸네일 이미지를 위해 JPG GD를 사용하여 썸네일 이미지를 생성한다. if ($img_size[0] > $img_size[1]) { //가로방향 이미지 if ($img_size[0] > $thumbnail_size) { $img_width = $thumbnail_size; $img_height = $img_size[1] * $thumbnail_size / $img_size[0]; } else { $img_width = $img_size[0]; $img_height = $img_size[1]; } } else { //세로방향 이미지 if ($img_size[1] > $thumbnail_size) { $img_width = $img_size[0] * $thumbnail_size / $img_size[1]; $img_height = $thumbnail_size; } else { $img_width = $img_size[0]; $img_height = $img_size[1]; } } if ($file[type] == "image/pjpeg" && (eregi("\\.jpg\$", $file[name]) || eregi("\\.jpeg\$", $file[name])) && $this->varGDPermit[jpg] == 'Y') { $dst_img = ImageCreate($img_width, $img_height); // 위에서 계산한대로 빈 이미지 파일을 만듭니다. $src_img = ImageCreateFromjpeg("{$upload_dir}/{$filename}"); // 이미지파일을 읽어들입니다. ImageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $img_width, $img_height, ImageSX($src_img), ImageSY($src_img)); //빈 이미지에다 원본이미지를 줄여서 그립니다. $creat_file_name = "{$thumbnail_upload_dir}/{$filename}"; Imagejpeg($dst_img, $creat_file_name, $thumbnail_quality); // thumb 디렉토리에 원본과 같은 이름의 jpeg으로 저장합니다. 76이라는 숫자는 퀄리티인데요, 높을수록 용량크고 질이 좋아집니다. } else { if ($file[type] == "image/x-png" && eregi("\\.png\$", $file[name]) && $this->varGDPermit[png] == 'Y') { $dst_img = ImageCreate($img_width, $img_height); // 위에서 계산한대로 빈 이미지 파일을 만듭니다. $src_img = ImageCreateFrompng("{$upload_dir}/{$filename}"); // 이미지파일을 읽어들입니다. ImageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $img_width, $img_height, ImageSX($src_img), ImageSY($src_img)); //빈 이미지에다 원본이미지를 줄여서 그립니다. $creat_file_name = "{$thumbnail_upload_dir}/{$filename}"; Imagepng($dst_img, $creat_file_name, $thumbnail_quality); // thumb 디렉토리에 원본과 같은 이름의 jpeg으로 저장합니다. 76이라는 숫자는 퀄리티인데요, 높을수록 용량크고 질이 좋아집니다. } else { if ($file[type] == "image/gif" && eregi("\\.gif\$", $file[name]) && $this->varGDPermit[gif] == 'Y') { $dst_img = ImageCreate($img_width, $img_height); // 위에서 계산한대로 빈 이미지 파일을 만듭니다. $src_img = ImageCreateFromgif("{$upload_dir}/{$filename}"); // 이미지파일을 읽어들입니다. ImageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $img_width, $img_height, ImageSX($src_img), ImageSY($src_img)); //빈 이미지에다 원본이미지를 줄여서 그립니다. $creat_file_name = "{$thumbnail_upload_dir}/{$filename}"; Imagegif($dst_img, $creat_file_name, $thumbnail_quality); // thumb 디렉토리에 원본과 같은 이름의 jpeg으로 저장합니다. 76이라는 숫자는 퀄리티인데요, 높을수록 용량크고 질이 좋아집니다. } else { $this->errmsg("{$file['type']}은 GD를 지원하지 않습니다!!"); } } } ImageDestroy($dst_img); //로드한 메모리를 비워줍니다. gd는 꼭 이걸 해주어야 합니다. ImageDestroy($src_img); }
function uploadimg($filename, $width, $get_height, $path) { if (trim($_FILES["image"]["tmp_name"]) != "") { $tmp_images = $_FILES["image"]["tmp_name"]; // type select if ($_FILES['image']['type'] == 'image/jpeg' or $_FILES['image']['type'] == 'image/jpg' or $_FILES['image']['type'] == 'image/pjpeg') { $images = $filename . ".jpg"; //upload source image $size = getimagesize($tmp_images); //check radio widht and height $height = round($width * $size[1] / $size[0]); if ($height > $get_height) { $width = round($get_height * $size[0] / $size[1]); $height = $get_height; } $images_orig = ImageCreateFromJPEG($tmp_images); $photoX = ImagesX($images_orig); $photoY = ImagesY($images_orig); $images_fin = ImageCreateTrueColor($width, $height); ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY); ImageJPEG($images_fin, $path . $images); ImageDestroy($images_orig); ImageDestroy($images_fin); return $filename . ".jpg"; } elseif ($_FILES['image']['type'] == 'image/x-png' or $_FILES['image']['type'] == 'image/png') { $images = $filename . ".png"; $size = getimagesize($tmp_images); //check radio widht and height $height = round($width * $size[1] / $size[0]); if ($height > $get_height) { $width = round($get_height * $size[0] / $size[1]); $height = $get_height; } $images_orig = ImageCreateFromPNG($tmp_images); $photoX = ImagesX($images_orig); $photoY = ImagesY($images_orig); $images_fin = ImageCreateTrueColor($width, $height); ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY); Imagepng($images_fin, $path . $images); ImageDestroy($images_orig); ImageDestroy($images_fin); return $filename . ".png"; } elseif ($_FILES['image']['type'] == 'image/gif') { $images = $filename . ".gif"; $size = getimagesize($tmp_images); //check radio widht and height $height = round($width * $size[1] / $size[0]); if ($height > $get_height) { $width = round($get_height * $size[0] / $size[1]); $height = $get_height; } $images_orig = ImageCreateFromgif($tmp_images); $photoX = ImagesX($images_orig); $photoY = ImagesY($images_orig); $images_fin = ImageCreateTrueColor($width, $height); ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY); Imagegif($images_fin, $path . $images); ImageDestroy($images_orig); ImageDestroy($images_fin); return $filename . ".gif"; } else { return FALSE; } } }
public function func_resize_save($dst_file, $src_file, $save_path, $max_x, $max_y) { $img_size = getimagesize($src_file); $img_replace = basename($src_file); switch ($img_size[2]) { //gif case 1: $src_img = ImageCreateFromgif($src_file); $dst_img = ImageCreateTrueColor($max_x, $max_y); ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $max_x, $max_y, $img_size[0], $img_size[1]); Imagegif($dst_img, $save_path . $img_replace, 100); break; //jpeg or jpg //jpeg or jpg case 2: $src_img = ImageCreateFromjpeg($src_file); $dst_img = ImageCreateTrueColor($max_x, $max_y); ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $max_x, $max_y, $img_size[0], $img_size[1]); Imagejpeg($dst_img, $save_path . $img_replace, 100); break; //png //png case 3: $src_img = ImageCreateFrompng($src_file); $dst_img = ImageCreateTrueColor($max_x, $max_y); ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $max_x, $max_y, $img_size[0], $img_size[1]); Imagepng($dst_img, $save_path . $img_replace, 9); break; } ImageDestroy($dst_img); ImageDestroy($src_img); }
function GD2_make_thumb_new($max_x, $max_y, $dst_name, $src_file) { $img_info = @getimagesize($src_file); $sx = $img_info[0]; $sy = $img_info[1]; //썸네일 보다 큰가? if ($sx > $max_x && $sy > $max_y) { if ($sx > $sy) { $thumb_y = ceil($sy * $max_x / $sx); $thumb_x = $max_x; } else { $thumb_x = ceil($sx * $max_y / $sy); $thumb_y = $max_y; } } else { if ($sx > $max_x) { $thumb_y = ceil($sy * $max_x / $sx); $thumb_x = $max_x; } else { if ($sy > $max_y) { $thumb_x = ceil($sx * $max_y / $sy); $thumb_y = $max_y; } else { $thumb_y = $sy; $thumb_x = $sx; } } } // JPG 파일인가? if ($img_info[2] == "2" or 1) { $_dq_tempFile = basename($src_file); //파일명 추출 $_dq_tempDir = str_replace($_dq_tempFile, "", $src_file); //경로 추출 $_dq_tempFile = $dst_name; //경로 + 새 파일명 생성 $_create_thumb_file = true; /* if (file_exists($_dq_tempFile)) { //섬네일 파일이 이미 존제한다면 이미지의 사이즈 비교 $old_img=@getimagesize($_dq_tempFile); if($old_img[0] != $thumb_x) $_create_thumb_file = true; else $_create_thumb_file = false; if($old_img[1] != $thumb_y) $_create_thumb_file = true; else $_create_thumb_file = false; } */ if ($_create_thumb_file) { // 복제 if ($img_info[2] == "1") { $src_img = ImageCreateFromgif($src_file); } if ($img_info[2] == "2") { $src_img = ImageCreateFromjpeg($src_file); } if ($img_info[2] == "3") { $src_img = ImageCreateFrompng($src_file); } if ($img_info[2] == "16") { $src_img = imagecreatefromwxbm($src_file); } if ($img_info[2] == "5") { $src_img = imagecreatefromwbmp($src_file); } if ($img_info[2] == "6") { $src_img = ImageCreateFromBMP($src_file); } if (!$src_img) { $src_img = imagecreatefromjpeg($src_file); } $dst_img = ImageCreateTrueColor($thumb_x, $thumb_y); ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_x, $thumb_y, $sx, $sy); Imagejpeg($dst_img, $_dq_tempFile, 100); // 메모리 초기화 ImageDestroy($dst_img); ImageDestroy($src_img); } } }
function create_thumb($img = "", $dir = "", $thumb_w = "", $thumb_h = "") { if (empty($thumb_h)) { $new_thumb = "{$img}"; } else { $new_thumb = "thumb_{$img}"; } if (!file_exists("{$dir}/{$img}")) { die("logo does not exist"); exit; } $ext = explode('.', $img); $ext = $ext[count($ext) - 1]; if (strtolower($ext) == "jpg") { $src_img = ImageCreateFromJPEG($dir . $img); } elseif (strtolower($ext) == "gif") { $src_img = ImageCreateFromgif($dir . $img); } else { die("Invalid picture format"); } $org_h = imagesy($src_img); $org_w = imagesx($src_img); if (empty($thumb_h)) { $thumb_h = floor($thumb_w * $org_h / $org_w); } else { $thumb_h = $thumb_h; } $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h); ImageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $org_w, $org_h); ImageJPEG($dst_img, "{$dir}/{$new_thumb}"); imageDestroy($src_img); }
private function createImageFromFile($file, $fileformat = 'jpg') { //TODO: png, gif etc support einbauen switch (strtolower($fileformat)) { case "jpg": case "jpeg": return ImageCreateFromJPEG($file); break; case "png": return ImageCreateFromPNG($file); break; case "wbmp": case "bmp": return imagecreatefromwbmp($file); break; case "gif": return ImageCreateFromgif($file); break; } }
function img_rotate() { $degree = I('get.degree'); $url = I('get.url'); //$url=dirname(__FILE__)."/verify.jpeg"; $source_info = getimagesize($url); $source_mime = $source_info['mime']; switch ($source_mime) { case 'image/gif': header('Content-type: image/gif'); $source = ImageCreateFromgif($url); $rotate = imagerotate($source, $degree, 0xffffff); imagegif($rotate); break; case 'image/jpeg': header('Content-type: image/jpeg'); $source = ImageCreateFromjpeg($url); $rotate = imagerotate($source, $degree, 0xffffff); imagejpeg($rotate); break; case 'image/png': header('Content-type: image/png'); $source = ImageCreateFrompng($url); $rotate = imagerotate($source, $degree, 0xffffff); imagepng($rotate); break; default: return false; break; } }