2011-12-18 3 views
0

그래서 이전에 여기에 나온 이미지의 크기를 조정하는 방법을 사용하고 있으며 처리하는 초기 이미지에 효과적이지만 두 번째로 프로세스를 사용합니다. 엄지 손톱에 사용할 작은 이미지를 만듭니다. 이 두 번째 엄지 손톱이 만들어지면 검정색 배경이 투명 해져야합니다. 비슷한 불만과 함께 여기에 많은 실을 보았 기 때문에 이것이 일반적인 문제라는 것을 알고 있습니다. 나는 PHP는 오류 로그에서 지난 밤에보고 때 그것은 ..... 그 imagecolorat이 범위를 벗어 났 픽셀을 칠려고 말한 일이 뭐죠PHP - 작은 이미지의 투명도 문제

PHP Notice: imagecolorat(): 0,28 is out of bounds in C:\inetpub\ 

은 적어도 나는 알고 있지만 내가 알아야 할 사항 지금 그것을 고치는 방법입니다. 정말 이상한 같은 이미지의 큰 복사본에 대한 나는이 오류를 전혀받지 못한다. 그리고 더 큰 업로드 된 사본의 멋진 사본을 만드는 것은 훌륭하게 작동한다. 나는 모든 것이 처음 실행을 위해하지만 방귀 두 번째 실행에 어떤 이유로 잘 작동과 범위 오류 아웃을 던져 말했듯이

$image_source = imagecreatefromstring($markericon); //original image 

    $imgHead = "image/jpeg"; //tag for image to be pulled later. images go in are png's 

//code to make sure image is never larger than certain size 
    $image_width = imagesx($image_source); 
    $image_height =  imagesy($image_source); 


    if($image_width>$max_upload_large_side || $image_height >$max_upload_large_side){ 
     $proportionslarge = $image_width/$image_height; 

     if($image_width>$image_height){ 
      $new_large_width = $max_upload_large_side; 
      $new_large_height = round($max_upload_large_side/$proportionslarge); 
     }  
     else{ 
      $new_large_height = $max_upload_large_side; 
      $new_large_width = round($max_upload_large_side*$proportionslarge); 
     }  

     $new_large_image = imagecreatetruecolor($new_large_width , $new_large_height); 

//code used to retain image transparency 


     //over write alpha chanel of image destination 
     imagealphablending($new_large_image, false); // Overwrite alpha 
     imagesavealpha($new_large_image, true); 

     // Create a separate alpha channel to blend images with 
     $alpha_image = imagecreatetruecolor($image_width, $image_height); 
     imagealphablending($alpha_image, false); // Overwrite alpha 
     imagesavealpha($alpha_image, true); 

     //copy data at every pixel in image 
     for ($x = 0; $x < $image_width; $x++) { 
     for ($y = 0; $y < $image_height; $y++) { 
     $alpha = (imagecolorat($image_source, $x, $y) >> 24) & 0xFF; 
     $color = imagecolorallocatealpha($alpha_image, 0, 0, 0, $alpha); 
     imagesetpixel($alpha_image, $x, $y, $color); 
            } 
            } 

     // Resize image to destination, using gamma correction 
     imagegammacorrect($image_source, 2.2, 1.0); 
     imagecopyresampled($new_large_image, $image_source, 0, 0, 0, 0, $new_large_width, $new_large_height, $image_width, $image_height); 
     imagegammacorrect($new_large_image, 1.0, 2.2); 

     // Resize alpha channel 
     $alpha_resized_image = imagecreatetruecolor($new_large_width, $new_large_height); 
     imagealphablending($alpha_resized_image, false); 
     imagesavealpha($alpha_resized_image, true); 

     imagecopyresampled($alpha_resized_image, $alpha_image, 0, 0, 0, 0, $new_large_width, $new_large_height, $image_width, $image_height); 

     // Copy alpha channel back to resized image 
     for ($x = 0; $x < $new_large_width; $x++) { 
     for ($y = 0; $y < $new_large_height; $y++) { 
     $alpha = (imagecolorat($alpha_resized_image, $x, $y) >> 24) & 0xFF; 
     $rgb = imagecolorat($new_large_image, $x, $y); 
     $r = ($rgb >> 16) & 0xFF; 
     $g = ($rgb >> 8) & 0xFF; 
     $b = $rgb & 0xFF; 
     $color = imagecolorallocatealpha($new_large_image, $r, $g, $b, $alpha); 
     imagesetpixel($new_large_image, $x, $y, $color); 
      } 
      } 



     // end of first run// 

     ob_start(); // Start capturing stdout. 
     imagePNG($new_large_image); 
     $lBinaryThumbnail = ob_get_contents(); // the raw jpeg image data. 
     ob_end_clean(); // Dump the stdout so it does not screw other output. 
     $lBinaryThumbnail = addslashes($lBinaryThumbnail); 
     imagedestroy($new_large_image);   
    } else $lBinaryThumbnail = $imgData; 


//start of second image run 
    if($image_width>$max_upload_small_side || $image_height >$max_upload_small_side){ 
     $proportionssmall = $image_width/$image_height; 

     if($image_width>$image_height){ 
      $new_small_width = $max_upload_small_side; 
      $new_small_height = round($max_upload_small_side/$proportionssmall); 
     }  
     else{ 
      $new_small_height = $max_upload_small_side; 
      $new_small_width = round($max_upload_small_side*$proportionssmall); 
     }  

     $new_small_image = imagecreatetruecolor($new_small_width , $new_small_height); 

     ////////////////////////////////////////////////////////////////////////////////// 

     //over write alpha chanel of image destination 
     imagealphablending($new_small_image, false); // Overwrite alpha 
     imagesavealpha($new_small_image, true); 

     // Create a separate alpha channel to blend images with 
     $alpha_image = imagecreatetruecolor($image_width, $image_height); 
     imagealphablending($alpha_image, false); // Overwrite alpha 
     imagesavealpha($alpha_image, true); 

     //copy data at every pixel in image 
     for ($x = 0; $x < $image_width; $x++) { 
     for ($y = 0; $y < $image_height; $y++) { 
     $alpha = (imagecolorat($image_source, $x, $y) >> 24) & 0xFF; 
     $color = imagecolorallocatealpha($alpha_image, 0, 0, 0, $alpha); 
     imagesetpixel($alpha_image, $x, $y, $color); 
            } 
            } 

     // Resize image to destination, using gamma correction 
     imagegammacorrect($image_source, 2.2, 1.0); 
     imagecopyresampled($new_small_image, $image_source, 0, 0, 0, 0, $new_small_width , $new_small_height, $image_width, $image_height); 
     imagegammacorrect($new_small_image, 1.0, 2.2); 

     // Resize alpha channel 
     $alpha_resized_image = imagecreatetruecolor($image_width, $image_height); 
     imagealphablending($alpha_resized_image, false); 
     imagesavealpha($alpha_resized_image, true); 

     imagecopyresampled($alpha_resized_image, $alpha_image, 0, 0, 0, 0, $new_small_width ,$new_small_height, $image_width, $image_height); 

     // Copy alpha channel back to resized image 
     for ($x = 0; $x < $new_small_width; $x++) { 
     for ($y = 0; $y < $new_small_height; $y++) { 
     $alpha = (imagecolorat($alpha_resized_image, $x, $y) >> 24) & 0xFF; 
     $rgb = imagecolorat($new_small_image, $x, $y); //this is the line that throws the error first and gives a out of bounds related error. 
     $r = ($rgb >> 16) & 0xFF; 
     $g = ($rgb >> 8) & 0xFF; 
     $b = $rgb & 0xFF; 
     $color = imagecolorallocatealpha($new_small_image, $r, $g, $b, $alpha); 
     imagesetpixel($new_small_image, $x, $y, $color); 
      } 
      } 



     // end of new code // 
     //imagecopyresampled($new_small_image, $image_source, 0, 0, 0, 0, $new_small_width, $new_small_height, $image_width, $image_height); 

     ob_start(); // Start capturing stdout. 
     imagePNG($new_small_image); 
     $sBinaryThumbnail = ob_get_contents(); // the raw jpeg image data. 
     ob_end_clean(); // Dump the stdout so it does not screw other output. 
     $sBinaryThumbnail = addslashes($sBinaryThumbnail); 
     imagedestroy($new_small_image);   
    } else $sBinaryThumbnail = $lBinaryThumbnail; 



    imagedestroy($image_source); 

: Heres는 필자가 사용하는 코드는 모든 크기를 조정합니다. 0,28에서 시작하여 50,50의 루프 프로세스가 끝날 때까지 계속됩니다.

답변

0

나는 알아 냈습니다. 위의 코드를 사용하여 알파 올바른 복사본을 만들고 그 코드를 모두 자신의 기능을 이제는 잘 작동합니다.

관련 문제