Foros del Web » Programando para Internet » PHP »

imagen negra al redimensionar con php y gd

Estas en el tema de imagen negra al redimensionar con php y gd en el foro de PHP en Foros del Web. Hola estoy redimensionando unas imagenes con php y la libreria gd y funciona pero cuando lo subo al servidor no funciona... me hace el corte ...
  #1 (permalink)  
Antiguo 16/04/2011, 23:13
Avatar de softmaster  
Fecha de Ingreso: diciembre-2008
Mensajes: 230
Antigüedad: 15 años, 4 meses
Puntos: 12
imagen negra al redimensionar con php y gd

Hola estoy redimensionando unas imagenes con php y la libreria gd y funciona pero cuando lo subo al servidor no funciona... me hace el corte pero solo muestra una imagen negra...


este es el codigo que estoy usando

Código PHP:
class Imagen 
          var 
$entrada ""
          var 
$width 0
          var 
$height 0
          var 
$tipo 0

          function 
Imagen($ent) { 
                   
$this->entrada $ent
                   list(
$wid$hei$tip) = getimagesize($ent); 
                   
$this->width $wid
                   
$this->height $hei
                   
$this->tipo $tip
          } 

          function 
getThumb($w$h$salida$opc false) { 
                   
$ent $this->entrada
                   
$tip $this->tipo
                   
$wid $this->width
                   
$hei $this->height

                   if (
$w) { 
                      
$newwidth $w
                      
$newheight round(($hei $wid) * $newwidth); 
                   }  elseif (
$h) { 
                      
$newheight $h
                      
$newwidth round(($wid $hei) * $newheight); 
                   } 
                   
// Cargar la imagen 
                   
$thumb imagecreatetruecolor($newwidth$newheight); 
                   if (
$tip == 1) { 
                      
$source imagecreatefromgif($ent); 
                   }  elseif (
$tip == 2) { 
                      
$source imagecreatefromjpeg($ent); 
                   }  elseif (
$tip == 3) { 
                      
$source imagecreatefrompng($ent); 
                   } 

                   
// Redimensionar 
                   
imagecopyresampled($thumb$source0000$newwidth$newheight$wid$hei); 

                   
// Mostrar la nueva imagen 
                   
if ($opc) return $thumb
                   else return 
imagejpeg($thumb$salida); 
          } 

          function 
getNothumb($w$h$salida$opc false) { 
                   
$ent $this->entrada
                   
$tip $this->tipo
                   
$wid $this->width
                   
$hei $this->height

                   if (
$h) { 
                      
$newheight $h
                      
$newwidth round(($wid $hei) * $newheight); 
                   }  else if (
$w) { 
                      
$newwidth $w
                      
$newheight round(($hei $wid) * $newwidth); 
                   } 
                   
// Cargar la imagen 
                   
$thumb imagecreatetruecolor($newwidth$newheight); 
                   if (
$tip == 1) { 
                      
$source imagecreatefromgif($ent); 
                   }  elseif (
$tip == 2) { 
                      
$source imagecreatefromjpeg($ent); 
                   }  elseif (
$tip == 3) { 
                      
$source imagecreatefrompng($ent); 
                   } 

                   
// Redimensionar 
                   
imagecopyresampled($thumb$source0000$newwidth$newheight$wid$hei); 

                   
// Mostrar la nueva imagen 
                   
if ($opc) return $thumb
                   else return 
imagejpeg($thumb$salida); 
          } 

          function 
getCorte($we$he$salida$opc false) { 
                   
$img $this->entrada
                   
$wid $this->width
                   
$hei $this->height
                   
$tip $this->tipo

                   if (
$wid $we $hei $he) { 
                      
$hp $hei
                      
$wp round(($we $he) * $hp); 
                   }  else { 
                      
$wp $wid
                      
$hp round(($he $we) * $wp); 
                   } 

                   
$lp round(($wid $wp) / 2); 
                   
$tp round(($hei $hp) / 2); 

                   
$thumb imagecreatetruecolor($we$he); 
                   if (
$tip == 1) { 
                     
$source imagecreatefromgif($img); 
                    }  elseif (
$tip == 2) { 
                     
$source imagecreatefromjpeg($img); 
                   }  elseif (
$tip == 3) { 
                     
$source imagecreatefrompng($img); 
                   } 

                   
imagecopyresampled($thumb$source00$lp$tp$we$he$wp$hp); 

                   if (
$opc) return $thumb
                   else return 
imagejpeg($thumb$salida); 
          } 
    } 

    if (isset(
$_GET["img"])) { 
       
$img = new Imagen($_GET["img"]); 
       
$tip $_GET["tip"]; 
       
$w $_GET["w"]; 
       
$h $_GET["h"]; 

       
header("Content-type: image/jpeg"); 
       if (
$tip == 0) { 
          
imagejpeg($img->getThumb($w$h""true)); 
       }  elseif (
$tip == 1) { 
          
imagejpeg($img->getNothumb($w$h""true)); 
       }  elseif (
$tip == 2) { 
          
imagejpeg($img->getCorte($w$h""true)); 
       } 
    } 
la unica diferencia que veo entre el hosting y mi servidor de prueba es que yo tengo "T1Lib Support" habilitado (true) y en el servidor no.. podra ser eso ? o es error de codigo...

alguna idea ?
  #2 (permalink)  
Antiguo 17/04/2011, 02:38
 
Fecha de Ingreso: noviembre-2009
Mensajes: 226
Antigüedad: 14 años, 5 meses
Puntos: 19
Respuesta: imagen negra al redimensionar con php y gd

Pues debe ser cosa del servidor... Llama a tu proveedor y preguntales... Un saludo!
__________________
Mi blog: magdkudama.com

Mi clase de validación de datos: magdkudama.com/validation
  #3 (permalink)  
Antiguo 17/04/2011, 02:47
Avatar de xalupeao  
Fecha de Ingreso: mayo-2008
Ubicación: Santiago, Chile
Mensajes: 749
Antigüedad: 15 años, 11 meses
Puntos: 12
Respuesta: imagen negra al redimensionar con php y gd

eso suele pasar cuando no detecta la fuente de donde proviene la imagen, puede que no estes guardando la imagen y no estes dando la ruta correcta.
__________________
Hosting en Chile en Silverhost - La solución en Hosting en Chile.
  #4 (permalink)  
Antiguo 17/04/2011, 15:07
Avatar de softmaster  
Fecha de Ingreso: diciembre-2008
Mensajes: 230
Antigüedad: 15 años, 4 meses
Puntos: 12
Respuesta: imagen negra al redimensionar con php y gd

Cita:
Iniciado por xalupeao Ver Mensaje
eso suele pasar cuando no detecta la fuente de donde proviene la imagen, puede que no estes guardando la imagen y no estes dando la ruta correcta.
si osea... le paso bien la ruta de la imagen...

si le envio una ruta de imagen muestra lo negro.. pero si genero una imagen guardada en la base de datos(binario) me lo muestra...

Etiquetas: libreriagd, redimensionar
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:26.