2013-07-08 3 views
0

이미지 업로드 시스템을 만들려고했지만 문제가 생겼습니다. 삽입 된 이미지가 업로드되고 미리보기가 생성됩니다.스크립트 업로드, 자르기/자르기 축소판 이미지

사용자가 축소판 너비와 높이를 지정할 수 있습니다. 이미지에서 200x100 픽셀이라고하고 사용자가 미리보기 이미지 너비를 10 픽셀로하고 높이를 20 픽셀로 말하면 시스템에서 이미지를 늘려야합니다. 나는 이미지가 스크립트를 통과 할 때 정상적인 섬네일과 이미지를 얻기 위해 Imagick 함수로 이미지의 일부를 잘라 내기를 원한다.

기능은 다음과 같이 사용됩니다

chopImage (width of the chopped area , height of the chopped area , x coordinate of topleft corner of chopped area , y coordinate of topleft corner of chopped area) 
PHP 업로드 시스템의

의 standart 구성 :

$image = $_FILES["image"]["name"]; 
      $imgtemp = $_FILES["image"]["tmp_name"]; 
      $imgtype = $_FILES["image"]["type"]; 
      $imgsize = $_FILES["image"]["size"];  

if(!$image){ 
     if($image_enabled ==2){ 
      $errors[] = "You didn't selected an image to upload"; 
      } 
     } else { 
    if($imgtype == 'image/jpeg'){ $filetype= '.jpg'; }else{ $filetype= str_replace ('image/', '', $imgtype); } 

    $path= 'images/' . md5(rand(0, 1000) . rand(0, 1000) . rand(0, 1000) . rand(0, 1000)) . '.jpg'; 
    $thumb_path= 'images/thumb_' . md5(rand(0, 1000) . rand(0, 1000) . rand(0, 1000) . rand(0, 1000)) . '.jpg'; 
    $imgsize2= getimagesize($imgtemp); 
    $width= $imgsize2[0]; 
    $height= $imgsize2[1]; 

    $maxwidth= 1281; 
    $maxheight= 721; 
    $allowed= array('image/png', 'image/jpeg', 'image/gif',); 

    if(in_array($imgtype, $allowed)){ 

     if($width < $maxwidth && $height < $maxheight){ 

     if($imgsize < 5242880){ 

내가 가진 stucked하고있는 부분 :이 프로그램을 실행할 때

    if(!isEmpty($image_thumbheight) || !isEmpty($image_thumbwidth)){ 

         switch($imgtype){ 
          case 'image/gif'; 
          $img= imagecreatefromgif($imgtemp); 
          $img_thumb= imagecreatefromgif($thumb); 
         header("Content-type: image/gif"); 
     $image_crop = new Imagick("$image"); 
     $image_crop->cropImage($image_thumbwidth,$image_thumbheight, 0,$height); 
     $image_crop->writeImage($thumb); 
     imagegif($thumb, $thumb_path); 
     break; 

         case 'image/png'; 
          $img= imagecreatefrompng($imgtemp); 

         header("Content-type: image/png"); 
     $image_crop = new Imagick("$imgtemp"); 
     $image_crop->chopImage($image_thumbwidth,$image_thumbheight, 0,$height); 
     $image_crop->writeImage($thumb); 
     imagepng($thumb, $thumb_path); 
     break; 
     case 'image/jpeg'; 
          $img= imagecreatefromjpeg($imgtemp); 
          $img_thumb= imagecreatefromjpeg($thumb); 
         header("Content-type: image/jpeg"); 
     $image_crop = new Imagick("$image"); 
     $image_crop->chopImage($image_thumbwidth,$image_thumbheight, 0,$height); 
     $image_crop->writeImage($thumb_path); 
     imagejpeg($thumb, $thumb_path); 
     break; 
         } 

       move_uploaded_file($imgtemp, $path); 
       echo "Image is successfully uploaded."; 
         } 

스크립트는 일반 이미지 만 업로드합니다. 미리보기 이미지는 업로드되지 않습니다. imagick 함수를 사용하여 인터넷에서 업로드 자습서를 찾을 수 없기 때문에 imagick 함수를 자주 사용하지 않습니다. 누군가 나를 도울 수 있습니까?

답변

0

코드가 약간 혼란 스럽습니다 ... 예상대로 작동합니까?

if(!isEmpty($image_thumbheight) || !isEmpty($image_thumbwidth)){ 
    $image_crop = new Imagick($imgtmp); 
    $image_crop->cropImage($image_thumbwidth, $image_thumbheight, 0, $height); 
    $image_crop->writeImage($thumb_path); 

    move_uploaded_file($imgtemp, $path); 
    echo "Image is successfully uploaded."; 
} 
관련 문제