Foros del Web » Programando para Internet » PHP »

Error en imágenes

Estas en el tema de Error en imágenes en el foro de PHP en Foros del Web. Hola, estoy haciendo un script en el que quiero crear una miniatura de una imagen. El código que tengo es: Código: <?php if ((empty($fecha)) or ...
  #1 (permalink)  
Antiguo 12/04/2006, 02:52
 
Fecha de Ingreso: agosto-2005
Mensajes: 40
Antigüedad: 18 años, 8 meses
Puntos: 0
Error en imágenes

Hola,

estoy haciendo un script en el que quiero crear una miniatura de una imagen. El código que tengo es:

Código:
<?php

if ((empty($fecha)) or $fecha=="0000-00-00")
$fecha=date("Y-m-d");

if(empty($idFoto))
{
	$sql="INSERT INTO fotos (nombre,descripcion,fecha) VALUES('".$nombre."','".$descripcion."','".$fecha."')";
	$query=mysql_query($sql,$con) OR error($con,$sql);
	$idFoto=mysql_insert_id($con);	
}
else
{
	$sql="UPDATE fotos SET nombre='".$nombre."',descripcion='".$descripcion."',fecha='".$fecha."' WHERE idFoto=".$idFoto;
	$query=mysql_query($sql,$con) OR error($con,$sql);
}
	
$pos_punto=strrpos($foto, ".");
$extension=substr($foto,$pos_punto,strlen($foto)-$pos_punto);

if (strtoupper($extension)==".JPG")  
{
	if(empty($idFoto))
	{
		unlink("../fotos/".$idFoto."_o.jpg");
		copy($foto_name,"../fotos/".$idFoto."_o.jpg");
	}
	else
	{
		$g="../fotos/".$idFoto."_o.jpg";
		copy($foto_name,$g);
	}
		
	//Funcion que comprueba la version de la librería de imágenes de PHP
	function gdVersion($user_ver = 0)
	{
	   if (! extension_loaded('gd')) { return; }
	   static $gd_ver = 0;
	   // Just accept the specified setting if it's 1.
	   if ($user_ver == 1) { $gd_ver = 1; return 1; }
	   // Use the static variable if function was called previously.
	   if ($user_ver !=2 && $gd_ver > 0 ) { return $gd_ver; }
	   // Use the gd_info() function if possible.
	   if (function_exists('gd_info')) {
		   $ver_info = gd_info();
		   preg_match('/\d/', $ver_info['GD Version'], $match);
		   $gd_ver = $match[0];
		   return $match[0];
	   }
	   // If phpinfo() is disabled use a specified / fail-safe choice...
	   if (preg_match('/phpinfo/', ini_get('disable_functions'))) {
		   if ($user_ver == 2) {
			   $gd_ver = 2;
			   return 2;
		   } else {
			   $gd_ver = 1;
			   return 1;
		   }
	   }
	   // ...otherwise use phpinfo().
	   ob_start();
	   phpinfo(8);
	   $info = ob_get_contents();
	   ob_end_clean();
	   $info = stristr($info, 'gd version');
	   preg_match('/\d/', $info, $match);
	   $gd_ver = $match[0];
	   return $match[0];
	}	
	
	$width=getimagesize($foto_name);
	$height=getimagesize($foto_name);
	$dfile="../../fotos/".$idFoto."_t.jpg";
	$sfile=$foto_name;
	
	//Redimensionamos la foto  en base al ancho
	$src_image = imagecreatefromjpeg($sfile);
	$w = $width;
	$h = $height;
	$src_w = imagesx($src_image);
	$src_h = imagesy($src_image);
	//establedemos las dimensiones del thumbnail
	if ($src_h>$src_w*1.7)
	{
		$zoom=$height/$src_h;
		$dst_h=$height;
		$dst_w=$src_w*$zoom;
	}
	else
	{
		$zoom=$width/$src_w;
		$dst_w=$width;
		$dst_h=$src_h*$zoom;
	}
	if (gdVersion()>=2) {
		$image = imageCreateTruecolor($dst_w, $dst_h);
		imageCopyResampled($image, $src_image, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h);
	}else{
		$image = imagecreate($dst_w, $dst_h);
		imagecopyresized($image, $src_image, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h);
	}
	//generamos la foto
	imagejpeg($image,$dfile);
	//liberamos la memoria
	imagedestroy($image);
	
	$res=1;
	
}
else
{
	$res=0;
}

?>

<script type="text/javascript">
	<!--document.location.href='index.php?seccion=fotos/editar_foto.php&idFoto=<?=$idFoto?>&idCategoriaFoto=<?=$idCategoriaFoto?>&pagina=<?=$pagina?>res=<?=$res?>';-->
</script>
Y los errores que me salen, unos provocados por anteriores son:

Código:
Warning: imagesx(): supplied argument is not a valid Image resource in /home/p2005183/public_html/wkk/admin/fotos/guardar_foto.php on line 82

Warning: imagesy(): supplied argument is not a valid Image resource in /home/p2005183/public_html/wkk/admin/fotos/guardar_foto.php on line 83

Warning: Division by zero in /home/p2005183/public_html/wkk/admin/fotos/guardar_foto.php on line 93

Warning: imagecreatetruecolor(): Invalid image dimensions in /home/p2005183/public_html/wkk/admin/fotos/guardar_foto.php on line 98

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/p2005183/public_html/wkk/admin/fotos/guardar_foto.php on line 99

Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/p2005183/public_html/wkk/admin/fotos/guardar_foto.php on line 105

Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/p2005183/public_html/wkk/admin/fotos/guardar_foto.php on line 107
¿Alguien me puede echar una mano?

Gracias.
  #2 (permalink)  
Antiguo 12/04/2006, 17:32
AlvaroG
Invitado
 
Mensajes: n/a
Puntos:
pos no veo que estés definiendo en ningún lugar la variable $foto_name, cuyo valor asignás a $sfile, que es la que usás como parámetro de imagecreatefromjpeg


Saludos.
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 07:50.