Ir para conteúdo
Fórum Script Brasil
  • 0

Arquivo de imagem inválido


vini_loock

Pergunta

Iai.

Estou tendo vários problemas para finalizar um esquema de upload de imagens, um deles é que se eu upar uma imagem com widht e height muito grandes ele da erro em algumas funções que eu estou usando, ele diz que a função não pode fazer uma imagem daquele tamanho, e coisas parecidas.

alguém sabe o porque?

O problema não é no tamanho em bit e sim nas dimenções, eu testei o script em uma imagem de + de 1 MB e foi normalmente, mas quando eu tentei em uma imagem de 100kB e com width=1600 e height=1100 ele me mostrou aquela montueira de erro.

As funções que mostraram erro foram:

imagecreatefrom*

images*

image*

imagecreatetruecolor

imagecopyresampled

Existe alguma configuração para estas funções?

Vlw.

Vinicius

Editado por vini_loock
Link para o comentário
Compartilhar em outros sites

3 respostass a esta questão

Posts Recomendados

  • 0

Erro:

Warning: imagesx(): supplied argument is not a valid Image resource in C:\wamp\www\pvr\image.class.php on line 72

Warning: imagesy(): supplied argument is not a valid Image resource in C:\wamp\www\pvr\image.class.php on line 73

Warning: Division by zero in C:\wamp\www\pvr\image.class.php on line 79

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\wamp\www\pvr\image.class.php on line 82

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\wamp\www\pvr\image.class.php on line 83

Warning: imagejpeg(): supplied argument is not a valid Image resource in C:\wamp\www\pvr\image.class.php on line 85

Warning: imagesx(): supplied argument is not a valid Image resource in C:\wamp\www\pvr\image.class.php on line 72

Warning: imagesy(): supplied argument is not a valid Image resource in C:\wamp\www\pvr\image.class.php on line 73

Warning: Division by zero in C:\wamp\www\pvr\image.class.php on line 79

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\wamp\www\pvr\image.class.php on line 82

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\wamp\www\pvr\image.class.php on line 83

Warning: imagejpeg(): supplied argument is not a valid Image resource in C:\wamp\www\pvr\image.class.php on line 85

Warning: imagesx(): supplied argument is not a valid Image resource in C:\wamp\www\pvr\image.class.php on line 72

Warning: imagesy(): supplied argument is not a valid Image resource in C:\wamp\www\pvr\image.class.php on line 73

Warning: Division by zero in C:\wamp\www\pvr\image.class.php on line 79

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\wamp\www\pvr\image.class.php on line 82

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\wamp\www\pvr\image.class.php on line 83

Warning: imagejpeg(): supplied argument is not a valid Image resource in C:\wamp\www\pvr\image.class.php on line 85

A classe:
<?php
    class Trataimagem{
        private $dr, $drforupload;
        private $tipos = array(01 => "image/jpg", 02 => "image/jpeg", 03 => "image/png", 04 => "image/gif", 05 => "image/bmp", 06 => "image/JPG", 07 => "image/JPEG", 08 => "image/PNG", 09 => "image/GIF", 10 => "image/BMP");
        private $image, $name, $tmp_name; 
        private $new_width, $new_height;
        public $created;
        
        function __construct($dr, $image){
            $this->dr = $dir;
            $this->image = $image;
            $this->name = explode(".", $this->image['name']);
            $this->tmp_name = $this->image['tmp_name'];
        }
        
        public function getCreated(){
            return $this->created;
        }
        
        public function valida(){
            if(in_array($this->image['type'], $this->tipos)){
                return true;
            }else{
                return false;
            }
        }
        
        public function upload($local){
            $this->drforupload = $local;
            $this->name[0] = 'image';
            while(file_exists($this->drforupload.$this->name[0].'.'.$this->name[1]) || file_exists($this->drforupload.$this->name[0].'.txt')){
                $this->name[0] = 'image'.rand(0, 999);
            }
            $move = move_uploaded_file($this->tmp_name, $this->drforupload.$this->name[0].'.'.$this->name[1]);
            if($move){
                return $this->drforupload.$this->name[0].'.'.$this->name[1];
            }else{
                return false;
            }
        }
        
        public function create($image){
            $name = explode(".", $image);
            switch($name[1]){
                case 'jpeg':
                    $create = imagecreatefromjpeg($image);
                    return $create;
                break;
                case 'jpg':
                    $create = imagecreatefromjpeg($image);
                    return $create;
                break;
                case 'png':
                    $create = imagecreatefrompng($image);
                    return $create;
                break;
                case 'gif':
                    $create = imagecreatefromgif($image);
                    return $create;
                break;
                default:
                    return false;
                break;
            }
        }
        
        public function resize($max_width, $max_height, $image, $salvar, $destino, $qualidade){
            $created = $this->create($image);
            $name = explode("/", $image);
            $num = count($name)-1;
            $name = explode(".", $name[$num]);
            $image_x = imagesx($created);
            $image_y = imagesy($created);
            
            if($image_y > $image_x){
                $pAltura = ceil(($max_height*100)/$image_y);
                $max_width = ceil(($image_x*$pAltura)/100);
            }else{
                $pLargura = ceil(($max_width*100)/$image_x);
                $max_height = ceil(($image_y*$pLargura)/100);
            }
            $create_new = imagecreatetruecolor($max_width, $max_height);
            imagecopyresampled($create_new, $created, 0, 0, 0, 0, $max_width, $max_height, $image_x, $image_y);
            if($salvar == 'true'){
                $salvar = imagejpeg($create_new, $destino.$name[0].'.jpg', $qualidade);
                if($salvar){
                    $this->created = $destino.$name[0].'.jpg';
                    return true;
                }else{
                    return false;
                }
            }
            if($create_new){
                return true;
            }else{
                return false;
            }
        }
        
        public function delete($arquivo){
            $dell = unlink($arquivo);
            $arquivose = explode(".", $arquivo);
            $fp = fopen($arquivose[0].'.txt', "a");
            fwrite($fp, "");
            fclose($fp);
            if($dell && $fp){
                return true;
            }else{
                return false;
            }
        }
    }
    
?>
O arquivo que está chamando a classe:
include 'image.class.php';
            $img = $_FILES['img'];
            $txt = $_POST['msg'];
            $data = date("Y-m-d");
            $hora = date("H:m:i");
            $error = array();
            if($img == ''){
                $error[] = 'Selecione uma imagem.';
            }
            if($txt == ''){
                $error[] = 'Digite um comentário.';
            }
            if($error[0] == ''){
                $classup = new Trataimagem("upload/ftuser/", $img);
                if($classup->valida()){
                    $up = $classup->upload("upload/ftuser/");
                    
                    $image_dm = getimagesize($up);
                    $image_x = $image_dm[0];
                    $image_y = $image_dm[1];
                    $classup->resize($image_x, $image_y, $up, 'true', 'upload/ftuser/normal/', 100);
            
                    $classup->resize(200, 200, $up, 'true', 'upload/ftuser/thumbs/', 40);
                    $classup->resize(500, 500, $up, 'true', 'upload/ftuser/grande/', 80);
                    $image = str_replace("upload/ftuser/grande/", "", $classup->getCreated());
                }
                $insert = mysql_query("INSERT INTO fotosusuarios (id, id_user, data, hora, img, texto) VALUES('', '$_SESSION[userid]', '$data', '$hora', '$image', '$txt')");
                
            }

Lembrando..

Esse sistema funciona perfeitamente com imagens de 800x600, mas tentei com uma de 1600x1100 deu erro.

Editado por vini_loock
Link para o comentário
Compartilhar em outros sites

  • 0

Vix... agora eu fui testar no servidor remoto, e está dando erro até nas imagens menores.

Fiz uma requisição mais simples e a lista de erro se alguém puder ajudar...

include 'image.class.php';
                    $upclass = new Trataimagem("upload/classificados/", $img);
                    if($upclass->valida()){
                        $upa = $upclass->upload("upload/classificados/");
                        
                        $upclass->resize(200, 200, $up, 'true', 'upload/classificados/thumbs/', 40);

Warning: imagesx(): supplied argument is not a valid Image resource in /home/portalta/public_html/image.class.php on line 72

Warning: imagesy(): supplied argument is not a valid Image resource in /home/portalta/public_html/image.class.php on line 73

Warning: Division by zero in /home/portalta/public_html/image.class.php on line 79

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /home/portalta/public_html/image.class.php on line 82

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/portalta/public_html/image.class.php on line 83

Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/portalta/public_html/image.class.php on line 85

Editado por vini_loock
Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      652k
×
×
  • Criar Novo...