Esempio n. 1
0
function resizeImgH($imgname, $height)
{
    $img_src = ImageCreateFromjpeg($imgname);
    $true_width = imagesx($img_src);
    $true_height = imagesy($img_src);
    $width = $height / $true_height * $true_width;
    $img_des = ImageCreateTruecolor($width, $height);
    imagecopyresampled($img_des, $img_src, 0, 0, 0, 0, $width, $height, $true_width, $true_height);
    return $img_des;
}
 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);
 }
 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);
 }
Esempio n. 4
0
 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);
 }
Esempio n. 5
0
 function resize_img($imgname, $size, $filename)
 {
     $filetype = $this->getFileExtension($imgname);
     $filetype = strtolower($filetype);
     switch ($filetype) {
         case "jpeg":
         case "jpg":
             $img_src = ImageCreateFromjpeg($imgname);
             break;
         case "gif":
             $img_src = imagecreatefromgif($imgname);
             break;
         case "png":
             $img_src = imagecreatefrompng($imgname);
             break;
     }
     $true_width = imagesx($img_src);
     $true_height = imagesy($img_src);
     if ($true_width >= $true_height) {
         $width = $size;
         $height = $width / $true_width * $true_height;
     } else {
         $width = $size;
         $height = $width / $true_width * $true_height;
     }
     $img_des = ImageCreateTrueColor($width, $height);
     imagecopyresampled($img_des, $img_src, 0, 0, 0, 0, $width, $height, $true_width, $true_height);
     // Save the resized image
     switch ($filetype) {
         case "jpeg":
         case "jpg":
             imagejpeg($img_des, $filename, 80);
             break;
         case "gif":
             imagegif($img_des, $filename, 80);
             break;
         case "png":
             imagepng($img_des, $filename, 80);
             break;
     }
 }
Esempio n. 6
0
 function reduit_fichier($fichier_image, $nomFinal, $max_v, $max_h, $source, $destination, $prefixe)
 {
     //if(call_user_func(array("Outils","extractExtension"),$fichier_image)!="jpg" && call_user_func(array("ajoutfichier","extractExtension"),$fichier_image)!="png")	return;
     if ($this->extractExtension($fichier_image) != "jpg" && $this->extractExtension($fichier_image) != "jpeg" && $this->extractExtension($fichier_image) != "png") {
         return;
     }
     // MAX_V = HAUTEUR -- MAX_H = LARGEUR
     // le nom de l'image "scalée" commencera par ti_ et le nom du fichier original
     $ti_fichier_image = $prefixe . $nomFinal;
     if (file_exists($destination . $ti_fichier_image)) {
         $ti_fichier_image = $prefixe . time() . "_" . $nomFinal;
     }
     //global $nomfichier;
     if ($this->extractExtension($fichier_image) == "png") {
         $im = ImageCreateFrompng($source . $fichier_image);
     } else {
         $im = ImageCreateFromjpeg($source . $fichier_image);
     }
     $v = ImageSY($im);
     // $v prend la hauteur
     $h = ImageSX($im);
     // $h prend la largeur
     //Floor Arrondi à l'entier inférieur
     //ON GERE LA HAUTEUR
     if ($v > $max_v) {
         // Si la hauteur Img, est plus grand que le max, on reduit
         $taux_hauteur = $v / $max_v;
         // On recupere le taux necessaire pour retrecir
         $ti_v = (int) floor($max_v);
         // ti_v = taille final de la hauteur
         $ti_h = (int) floor($h / $taux_hauteur);
         // ti_h = taille final de la largeur
     } else {
         $ti_v = $v;
     }
     // Sinon on fixe la hauteur
     // Si il n'a pas deja subi une modification de la taille
     if ($ti_h != "") {
         $h_comp = $ti_h;
     } else {
         $h_comp = $h;
     }
     if ($ti_v != "") {
         $v_comp = $ti_v;
     } else {
         $v_comp = $v;
     }
     //ON GERE LA LARGEUR
     if ($h_comp > $max_h) {
         $taux_largeur = $h_comp / $max_h;
         $ti_h = (int) floor($max_h);
         $ti_v = (int) floor($v_comp / $taux_largeur);
     } else {
         $ti_h = $h_comp;
     }
     $ti_im = ImageCreateTrueColor($ti_h, $ti_v);
     imagecopyresampled($ti_im, $im, 0, 0, 0, 0, $ti_h, $ti_v, $h, $v);
     if ($this->extractExtension($fichier_image) == "png") {
         imagepng($ti_im, "{$destination}" . "{$ti_fichier_image}");
     } else {
         imagejpeg($ti_im, "{$destination}" . "{$ti_fichier_image}");
     }
     return $nomfichier = $ti_fichier_image;
 }
Esempio n. 7
0
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);
        }
    }
}
Esempio n. 8
0
imagettftext($finalimage, 9, 0, 35, 376, $black, $font, $level . "%");
$value = array(2, 19, 7, 101, 27, 101, 27, 19);
imagefilledpolygon($finalimage, $value, 4, $red);
$value = array(7, 102, 12, 162, 27, 162, 27, 102);
imagefilledpolygon($finalimage, $value, 4, $orange);
$value = array(12, 163, 17, 221, 27, 221, 27, 163);
imagefilledpolygon($finalimage, $value, 4, $yellow);
$value = array(17, 222, 22, 281, 27, 281, 27, 222);
imagefilledpolygon($finalimage, $value, 4, $yellgr);
$value = array(22, 282, 27, 348, 27, 348, 27, 282);
imagefilledpolygon($finalimage, $value, 4, $green);
imagefilledellipse($finalimage, 65, 101, 6, 6, $red);
imagefilledellipse($finalimage, 65, 161, 6, 6, $orange);
imagefilledellipse($finalimage, 65, 221, 6, 6, $yellow);
imagefilledellipse($finalimage, 65, 281, 6, 6, $yellgr);
imagefilledellipse($finalimage, 65, 346, 6, 6, $green);
if ($t_current > $t_max) {
    $burstImg = ImageCreateFromjpeg('burst.jpg');
    $burstW = ImageSX($burstImg);
    $burstH = ImageSY($burstImg);
    ImageCopy($finalimage, $burstImg, 0, 0, 0, 0, $burstW, $burstH);
}
//Create the final image
Imagejpeg($finalimage, NULL, 99);
//Destroy de rest of images
Imagedestroy($finalimage);
Imagedestroy($thermImage);
Imagedestroy($thermbarImage);
?>
 
Esempio n. 9
0
 function resize_img($imgname, $size, $filename)
 {
     if (!file_exists(App::pluginPath('PageManager') . 'webroot' . DS . 'img' . DS . $filename)) {
         $filetype = $this->getFileExtension(App::pluginPath('PageManager') . 'webroot' . DS . 'img' . DS . $imgname);
         $filetype = strtolower($filetype);
         switch ($filetype) {
             case "jpeg":
             case "jpg":
                 $img_src = ImageCreateFromjpeg(App::pluginPath('PageManager') . 'webroot' . DS . 'img' . DS . $imgname);
                 break;
             case "gif":
                 $img_src = imagecreatefromgif(App::pluginPath('PageManager') . 'webroot' . DS . 'img' . DS . $imgname);
                 break;
             case "png":
                 $img_src = imagecreatefrompng(App::pluginPath('PageManager') . 'webroot' . DS . 'img' . DS . $imgname);
                 break;
         }
         $true_width = imagesx($img_src);
         $true_height = imagesy($img_src);
         // if ($true_width>=$true_height)
         // {
         //         $width=$size;
         //         $height = ($width/$true_width)*$true_height;
         // }
         // else
         // {
         $height = $size;
         $width = $height / $true_height * $true_width;
         // }
         $img_des = ImageCreateTrueColor($width, $height);
         imagecopyresampled($img_des, $img_src, 0, 0, 0, 0, $width, $height, $true_width, $true_height);
         // Save the resized image
         switch ($filetype) {
             case "jpeg":
             case "jpg":
                 imagejpeg($img_des, App::pluginPath('PageManager') . 'webroot' . DS . 'img' . DS . $filename, 80);
                 break;
             case "gif":
                 imagegif($img_des, App::pluginPath('PageManager') . 'webroot' . DS . 'img' . DS . $filename, 80);
                 break;
             case "png":
                 imagepng($img_des, App::pluginPath('PageManager') . 'webroot' . DS . 'img' . DS . $filename, 7);
                 break;
         }
     }
     if (file_exists(App::pluginPath('PageManager') . 'webroot' . DS . 'img' . DS . $filename)) {
         return $filename;
     }
 }
Esempio n. 10
0
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;
    }
}