Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

GiovanniDT

Thumbnails Negras

Recommended Posts

Olá ,

 

Quando o upload de uma imagem passa como endereço uma imagem na internet (fora de meu host) a imagem dos thumbnails ficam negros.

 

Eis meu código:

 


       public function createThumb($file, $new_w = 115, $new_h = 115){

//NAME MANAGEMENT:
      $name = $file['name'];
      $nameParts = explode('.', $name);
      $cleanName = cleanFileName($name);
      $cleanNameParts = explode('.', $cleanName);

if (preg_match('/jpg|jpeg/',$nameParts[1])){

	$src_img = imagecreatefromjpeg("C:\wamp\www\OOP_Teste\publico\imagens" . "\\" . $file['name']);
}

if (preg_match('/png/',$nameParts[1])){

	$src_img = imagecreatefrompng("C:\wamp\www\OOP_Teste\publico\imagens" . "\\" .$file['name']);
}

       $old_x = imageSX($src_img);
       $old_y = imageSY($src_img);

       if ($old_x > $old_y) {

               $thumb_w = $new_w;
               $thumb_h = $old_y*($new_h/$old_x);
       }

       if ($old_x < $old_y) {

               $thumb_w = $old_x*($new_w/$old_y);
               $thumb_h = $new_h;
       }

       if ($old_x == $old_y) {

               $thumb_w = $new_w;
               $thumb_h = $new_h;

       }

       $dst_img = ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);

           if (preg_match("/png/",$name[1])){
                   imagepng($dst_img, "C:/wamp/www/OOP_Teste/publico" . DS. $this->upload_dir . DS . $this->thumb_dir . DS . $cleanNameParts[0] . "_thumb.png");
           } elseif (preg_match("/jpg|jpeg/",$name[1])) {
                   imagejpeg($dst_img, "C:/wamp/www/OOP_Teste/publico" . DS. $this->upload_dir . DS . $this->thumb_dir . DS . $cleanNameParts[0] . "_thumb.jpg");
           } elseif (preg_match("/gif/",$name[1])) {
                   imagejpeg($dst_img, "C:/wamp/www/OOP_Teste/publico" . DS. $this->upload_dir . DS . $this->thumb_dir . DS . $cleanNameParts[0] . "_thumb.gif");
           }

           imagedestroy($dst_img); 
           imagedestroy($src_img);

  }

Compartilhar este post


Link para o post
Compartilhar em outros sites

$src_img = imagecreatefromjpeg("C:\wamp\www\OOP_Teste\publico\imagens" . "\\" . $file['name']);

Olha esse trecho.

 

Se você colocar uma imagem com endereço:

 

Você tentará redimensionar uma imagem com caminho:

C:\wamp\www\OOP_Teste\publico\imagens\http://seusite.com/imagem.jpg

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

Na verdade não, ele pega o nome da variável $file , esta variável é um parametro que busca no arquivo enviado por post -> $_FILE['uploaded']. Então o que ele pega seria um $_File['name'], que é "nome do arquivo" . "." . "extensão";

O problema não é este, mas ainda não sei qual é.

 

Obrigado mesmo assim.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.