Foros del Web » Programando para Internet » PHP »

CodeIgniter Al crear un thumbnail muestra una imagen negra

Estas en el tema de Al crear un thumbnail muestra una imagen negra en el foro de PHP en Foros del Web. Hola, estoy creando un sitio web en codeigniter y uno de sus controladores se dedica a crear imagenes de un tamaño dado. En mi servidor ...
  #1 (permalink)  
Antiguo 04/09/2011, 04:23
 
Fecha de Ingreso: septiembre-2011
Mensajes: 2
Antigüedad: 12 años, 7 meses
Puntos: 2
Al crear un thumbnail muestra una imagen negra

Hola,
estoy creando un sitio web en codeigniter y uno de sus controladores se dedica a crear imagenes de un tamaño dado.

En mi servidor local funciona todo correctamente y las imágenes se ven redimensionadas pero al subirlo al servidor remoto todas las imagenes se muestran de color negro.

Demomento solo he probando con imágenes JPG.

Aquí les paso el código del controlador:

Código PHP:

<?php
class imager extends Controller {

    public 
$path;

    function 
imager() {
        
parent::Controller();
        
//Start properties
        
$this->path base_url().'img/CASAS/';
    }

    function 
showthumb($name$width 100$height 100)
    {
        
$imagen $this->_createImage($this->path$name);
        
$destino $this->_escalar($imagen$width$height);
        
$this->_displayImage($destino$this->path.$name);
        
imagedestroy($imagen);
        
iamgedestroy($destino);
    }

    function 
_displayImage($img$name)
    {
        
header('Content-type: image/jpeg');

        if (
preg_match('/.jpg|.jpeg|.JPG/'$name)) {
            
imagejpeg($img);
        }else if (
preg_match('/.png|.PNG/'$name)) {
            
imagepng($img);
        }else if (
preg_match('/.gif|.GIF/'$name)) {
            
imagegif($img);
        }
    }

    function 
_createImage($path$name)
    {
        if (
preg_match('/.jpg|.jpeg|.JPG/'$name)) {
            
$imagen imagecreatefromjpeg($path.$name);
        }else if (
preg_match('/.png|.PNG/'$name)) {
            
$imagen imagecreatefrompng($path.$name);
        }else if (
preg_match('/.gif|.GIF/'$name)) {
            
$imagen imagecreatefromgif($path.$name);
        }else
            return 
false;

        return 
$imagen;
    }

    function 
_escalar($img$width$height)
    {
        
$x imageSX($img);
        
$y imageSY($img);

        
$dest imagecreatetruecolor($width$height);
        
imagecopyresized($dest$img0000$width$height$x$y);

        return 
$dest;
    }
}
Aquí les paso la información del módulo GD en ambos servidores:

Localhost :

gd

GD Support enabled
GD Version 2.0
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.4.4
T1Lib Support enabled
GIF Read Support enabled
GIF Create Support enabled
JPEG Support enabled
libJPEG Version 6b
PNG Support enabled
libPNG Version 1.2.44
WBMP Support enabled

Servidor remoto

gd

GD Support enabled
GD Version bundled (2.0.34 compatible)
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.2.1
GIF Read Support enabled
GIF Create Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
XBM Support enabled


Muchas gracias por la ayuda, que seria muy de agradecer ya que no consigo dar con la solución.

SOLUCIÓN

El problema residia en la manera de buscar las imágenes.

Cita:
$this->path = base_url().'img/CASAS/';
base_rul() es un parámetro de configuración de Codeigniter que devuelve la URL Ej: http://www-midominio.com/

Al substituir esa linea por
Cita:
$this->path = $_SERVER['DOCUMENT_ROOT'].'/img/CASAS/';
todo funcionó!

Última edición por antzo90; 04/09/2011 a las 05:19 Razón: Solucionado
  #2 (permalink)  
Antiguo 04/09/2011, 10:22
Avatar de maycolalvarez
Colaborador
 
Fecha de Ingreso: julio-2008
Ubicación: Caracas
Mensajes: 12.120
Antigüedad: 15 años, 9 meses
Puntos: 1532
Respuesta: Al crear un thumbnail muestra una imagen negra

Excelente que lo solucionaras tú solo
__________________
¡Por favor!: usa el highlight para mostrar código
El que busca, encuentra...

Etiquetas: codeigniter, imagenes, muestra, negra, thumbnails
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

SíEste tema le ha gustado a 2 personas




La zona horaria es GMT -6. Ahora son las 16:47.