Erro Redimensionar Imagem PHP

silvino

Power Member
Olá,

Estou a ter problemas para redimensionar imagens, o script ultrapassa os 32 megabytes impostos pelo hoster...
Será problema do Script ? Afinal as imagens não são assim tão grandes,,,
PHP:
public function imgresize($id, $timg) {
        //Função que altera o tamanho das imagens
        //$imgsrc caminho para a imagem
        //$infoimg dados da imagem original
        //$img dita cuja imagem a alterar 
        //$nimg imagem criada com novas dimensões

        $imgsrc = $this->imgroot.$id;
        $infoimg = getimagesize($imgsrc);

        //determina o tamanho que a imagem terá 
        if($infoimg[0]>0 AND $infoimg[1]>0){ 
            $width=$infoimg[0]; 
            $height=$infoimg[1]; 
        }else{ 
            return $id." imgsize ?"; 
             
        }     
        if ($width > $height) { 
            $percent = ($timg / $width); 
        } else { 
            $percent = ($timg / $height); 
        } 
         
        //calcula o novo tamanho e arredonda o resultado 
        $width = round($width * $percent); 
        $height = round($height * $percent);
        //Cria uma imagem com o tamanho pretendido 
        
        $nimg = imagecreatetruecolor($width, $height);
        
        //determina o tipo de imagem e
        //Copia a imagem original para a nova, alterando o seu tamanho 
        switch($infoimg["2"]){
            case "1":
                //1 = GIF,
                imagecopyresampled($nimg, imagecreatefromgif($imgsrc), 0, 0, 0, 0, $width, $height, $infoimg[0], $infoimg[1]);
            break;
            case "2":
                //2 = JPG,
                imagecopyresampled($nimg, imagecreatefromjpeg($imgsrc), 0, 0, 0, 0, $width, $height, $infoimg[0], $infoimg[1]);
            break;
            case "3":
                //3 = PNG,
                imagecopyresampled($nimg, imagecreatefrompng($imgsrc), 0, 0, 0, 0, $width, $height, $infoimg[0], $infoimg[1]);
            break;                            
            default:
            //4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF(intel byte order),
            //8 = TIFF(motorola byte order), 9 = JPC, 10 = JP2,
            //11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF
                return FALSE;
        }
        
         //remove a imagem anterior e guarda a nova 
         if(unlink($imgsrc)){
            if($this->imggrava($nimg ,$id, $infoimg["2"])){
                return "TRUE";
            }
         }
         return "FALSE";
 }

Até Já.
 
Back
Topo