Foros del Web » Programando para Internet » PHP »

Problema con thumbnail

Estas en el tema de Problema con thumbnail en el foro de PHP en Foros del Web. Hola, estoy utilizando intentando mostrar una imágen alojada en el servidor, y el problema es que al hacerlo redimensionandola para que salga proporcional me muestra ...
  #1 (permalink)  
Antiguo 26/03/2011, 15:54
 
Fecha de Ingreso: mayo-2010
Mensajes: 128
Antigüedad: 14 años
Puntos: 13
Problema con thumbnail

Hola, estoy utilizando intentando mostrar una imágen alojada en el servidor, y el problema es que al hacerlo redimensionandola para que salga proporcional me muestra solo el código ascci, no la imagen. Tengo activadas las librarias GD en el PHP.
Dejo la parte del código que interesa

Código:
<?php
require_once("conexion.php");
require_once("funciones.php");
$fechadia = @strtotime($_GET["dia"]);
$imagen=$_GET["anuncio"];
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title><?php echo $_GET["titulo"];?></title>
<link href="estilos.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="contenedor">  
  <div id="cabecera">Esta es la cabecera</div>
  <div id="lateralizq">
  <table>
  <tr>
  	<td width="145" align="center"><a href="javascript:window.history.back()">Anterior</a></td>
  </tr>
  <tr>
  	<td align="center"><strong><?php echo strtoupper($_GET["ciudad"]);?></strong></td>
  </tr>
  <tr>
  	<td>
<?php
$sql="select nombre from secciones";
listado($sql,$_GET['ciudad']);
setlocale(LC_TIME,"spanish");
?>
  	</td>
  </tr>
  </table>
  </div>
	<div id="contenido">
          <table width="450">
            <tr>
              <td width="330" align="left"><p style="margin:10px">Enviado el&nbsp;<?php echo strftime("%d de %B del %Y",$fechadia);?>&nbsp;a las&nbsp;<?php echo substr($_GET["hora"],0,-3);?>&nbsp;horas</p></td>
            </tr>
            <tr>
              <td bgcolor="#C2C8E2"><h2 style="margin:0px"><?php echo $_GET["titulo"];?></h2></td>
              <td width="105" bgcolor="#C2C8E2"><h3 style="margin:0px"><?php echo $_GET["precio"];?>&nbsp;Euros</h3></td>            
            </tr>
            <tr>
            	<td colspan="2"><h4 style="margin-top:0px" style="margin:1px">(<?php echo $_GET["tipo"];?>)</h4></td>
            </tr>
            <?php
			// SI EXISTE LA IMAGEN LA MOSTRAMOS
			// COLOCO LA IMAGEN 115 SOLO DEMOMENTO PARA PROBAR SI FUNCIONA Y SABIENDO QUE ESTA EN EL LOCALHOST
			if (file_exists("$_GET[seccion]/$_GET[tipo]/$_GET[anuncio].jpg"))
			{
			?>
            <tr align="center">
              <td align="center" colspan="2"><IMG SRC="http://localhost/bbddfolder/<?php echo $_GET["seccion"];?>/<?php echo $_GET["tipo"];?>/<?php redimensionar_foto('115.jpeg');?>></IMG></td>
            </tr>
            <?php
AQUI LA FUNCION A LA QUE SE LLAMA PARA MOSTRAR LA IMAGEN

Código:
function redimensionar_foto($filename)
{

// Variables que indican el archivo de la imagen y el nuevo tamano

$porcentaje = 0.5;

// Content-type para el navegador
header('Content-type: image/jpeg');

// Se obtienen las nuevas dimensiones
list($width, $height) = getimagesize($filename);
$newwidth = $width * $porcentaje;
$newheight = $height * $porcentaje;

// Cargar la imagen
$thumb = imagecreate($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

// Redimensionar
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Mostrar la nueva imagen
imagejpeg($thumb);
}
Y este es el error:

Enviado el 11 de marzo del 2011 a las 01:00 horas
Nvidia

15 Euros
(Tarjetas Gráficas)
< å·@ã¡NE�kjŸ|3§^}‚Þæm[Qíg¥Bnd8Îy_—#‚síTÇŠž]Î?wôPœµïÅ»2ZM+Â÷ëék4±“ÿ�|WŸD˜Eã/ jz"– ö¤Å;O« ý�c^—L’(åFI]meaÃÐûP='YÓu˾Ó/ »¶~’Bá†}¡äpy~¼Ã[øeq£ê¯|>¹N¥Ök ÿ�¢Ý~R½©Çn˜Ú~jØð'Ä|RgÓoíÛNñˆÅå„ ‚0q¹3ÕrG¸ÈëHoEPEPEPEPEPEPEPEPX0 ñ]Ÿƒô u;µi"8 O¿<§;Q~¸?@ ç¼Ý+ËtXÇĉ·šìÛ%м;)³Ó€V[® ’õ9Ç?îÈ4§à¯ß6¦þ0ñiYüEt˜Ž/Oˆò#Œv88'ÜŽrŽ� P* «Ë{4F¸•#W‘bRÇf!TrH=”´�QE�QE�Wž|Fð,ÚºÅâ? mâ}7÷¶òÇ€g�«nÇ=xìx5èt„q................
  #2 (permalink)  
Antiguo 26/03/2011, 19:03
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: Problema con thumbnail

Debes enviar un encabezado de acuerdo al contenido, para que el navegador pueda interpretar correctamente lo que esta recibiendo:

Esta linea:
header('Content-Type: image/jpeg');

Antes de enviar la imagen debe solucionarte el problema.
__________________
- León, Guanajuato
- GV-Foto
  #3 (permalink)  
Antiguo 27/03/2011, 07:05
 
Fecha de Ingreso: mayo-2010
Mensajes: 128
Antigüedad: 14 años
Puntos: 13
Respuesta: Problema con thumbnail

Quieres decir que ponga header('Content-Type: image/jpeg'); al comienzo del fichero principal y no en la función? El tema es que si hago eso me saca este resultado:

http://localhost/bbddFolder/anuncio.php?titulo=Nvidia&seccion=Hardware&.......

No se porque solo me muestra los parametros que se recogen por GET de la página anterior... todo lo demás lo obvia.
  #4 (permalink)  
Antiguo 27/03/2011, 19:11
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: Problema con thumbnail

Lo mejor seria que hagas tu etiqueta <img src="miniaturas.php?id=####" />

Y en miniaturas.php lo unico que haces es obtener la ID, procesar la imagen y presentarla con sus respectivos encabezados.
__________________
- León, Guanajuato
- GV-Foto

Etiquetas: 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




La zona horaria es GMT -6. Ahora son las 02:25.