Foros del Web » Programando para Internet » PHP »

Loco con los thumbnails...

Estas en el tema de Loco con los thumbnails... en el foro de PHP en Foros del Web. Ya he perdido la cuenta de las variantes de lo mismo que he probado, funciones, clases, código... simplemente quiero un código para crear thumbnails de ...
  #1 (permalink)  
Antiguo 06/04/2009, 08:18
Avatar de Freakme  
Fecha de Ingreso: julio-2007
Ubicación: Portugalete
Mensajes: 97
Antigüedad: 16 años, 8 meses
Puntos: 0
Loco con los thumbnails...

Ya he perdido la cuenta de las variantes de lo mismo que he probado, funciones, clases, código... simplemente quiero un código para crear thumbnails de imagenes que subo a mi página.
Este es el último ejemplo que he probado:
Esto es resize.php

Código:
<?php

/*
	Version 1.0 Created by: Ryan Stemkoski
	Questions or comments: [email protected]
	Visit us on the web at: http://www.ipowerplant.com
	Purpose:  This script can be used to resize one or more images.  It will save the file to a directory and output the path to that directory which you 
			  can display or write to a databse. 
	
	TO USE, SET: 
		$filename = image to be resized
		$newfilename = added to filename to for each use to keep from overwriting images created example thumbnail_$filename is how it will be saved.
		$path = where the image should be stored and accessed. 
		$newwidth = resized width could be larger or smaller
		$newheight = resized height could be larger or smaller
		
	SAMPLE OF FUNCTION: makeimage('image.jpg','fullimage_','imgs/',250,250)
	
	Include the file containing the function in your document and simply call the function with the correct parameters and your image will be resized.
	
*/
 
//IMAGE RESIZE FUNCTION FOLLOW ABOVE DIRECTIONS
function makeimage($filename,$newfilename,$path,$newwidth,$newheight) {

	//SEARCHES IMAGE NAME STRING TO SELECT EXTENSION (EVERYTHING AFTER . )
	$image_type = strstr($filename, '.');

	//SWITCHES THE IMAGE CREATE FUNCTION BASED ON FILE EXTENSION
		switch($image_type) {
			case '.jpg':
				$source = imagecreatefromjpeg($filename);
				break;
			case '.png':
				$source = imagecreatefrompng($filename);
				break;
			case '.gif':
				$source = imagecreatefromgif($filename);
				break;
			default:
				echo("Error Invalid Image Type");
				die;
				break;
			}
	
	//CREATES THE NAME OF THE SAVED FILE
	$file = $newfilename . $filename;
	
	//CREATES THE PATH TO THE SAVED FILE
	$fullpath = $path . $file;

	//FINDS SIZE OF THE OLD FILE
	list($width, $height) = getimagesize($filename);

	//CREATES IMAGE WITH NEW SIZES
	$thumb = imagecreatetruecolor($newwidth, $newheight);

	//RESIZES OLD IMAGE TO NEW SIZES
	imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

	//SAVES IMAGE AND SETS QUALITY || NUMERICAL VALUE = QUALITY ON SCALE OF 1-100
	imagejpeg($thumb, $fullpath, 60);

	//CREATING FILENAME TO WRITE TO DATABSE
	$filepath = $fullpath;
	
	//RETURNS FULL FILEPATH OF IMAGE ENDS FUNCTION
	return $filepath;

}

?>
y esto es index.php
Código:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
</head>
<? include("resize.php"); ?>
<body>
<table width="813" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="231" height="19"><strong>ORGINAL IMAGE:</strong></td>
  </tr>
  <tr>
    <td height="19"><img src="retrato.jpg"></td>
  </tr>
</table>
<p>&nbsp;</p>
<table width="813" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="231" height="19"><strong>RESIZED IMAGE:</strong></td>
  </tr>
  <tr>
    <td height="19"><img src="<? echo(makeimage('retrato.jpg','thumbnail_','',200,250)); ?>"></td>
  </tr>
</table>
</body>
</html>
Cuando lo pruebo en local, con el xampp, me funciona perfectamente, me crea el thumbnail, me crea un archivo llamado "thumbnail_retrato.jpg", perfecto. Pero cuando lo subo al hospedaje no funciona, no crea el thumbnail.
¿¿Alguien puede ayudarme??
Tengo el hospedaje con www.hospedajeydominios.com, ¿alguien más lo tiene ahí? ¿alguien que pueda decirme cómo hacer funcionar esto?

Edito:
Desde la atención al cliente del hospedaje me escriben que es un hospedaje con php4 (safe mode), y que revise que el código sea compatible con esto.

Última edición por Freakme; 06/04/2009 a las 08:29
  #2 (permalink)  
Antiguo 06/04/2009, 09:18
Avatar de emiliodeg  
Fecha de Ingreso: septiembre-2005
Ubicación: Córdoba
Mensajes: 1.830
Antigüedad: 18 años, 7 meses
Puntos: 55
Respuesta: Loco con los thumbnails...

tu hosting tiene la libreria GD habilitada? cuanta memoria tiene php para trabajar?
esas son las 2 mas fallas
puedes verlo haciendo un phpinfo(); en un archivito cualquiera
__________________
Degiovanni Emilio
developtus.com
  #3 (permalink)  
Antiguo 06/04/2009, 09:58
 
Fecha de Ingreso: diciembre-2005
Ubicación: Vigo
Mensajes: 135
Antigüedad: 18 años, 3 meses
Puntos: 3
Respuesta: Loco con los thumbnails...

Ademas de lo que te comena emiliodeg, comprueba los permisos en la carpeta donde quieres crear los thumbnails, tendrias que tener 777.
__________________
AlfaMeta formacion
  #4 (permalink)  
Antiguo 06/04/2009, 10:31
Avatar de Ronruby  
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 9 meses
Puntos: 416
Respuesta: Loco con los thumbnails...

Tambien usa las etiquetas de PHP completas, <?php y ?>
  #5 (permalink)  
Antiguo 07/04/2009, 04:01
Avatar de Freakme  
Fecha de Ingreso: julio-2007
Ubicación: Portugalete
Mensajes: 97
Antigüedad: 16 años, 8 meses
Puntos: 0
Respuesta: Loco con los thumbnails...

Gracias a todos, después de un buen montón de emails con el servicio técnico del hospedaje llegamos a la solución. Como dice Subirol eran los permisos, maldito 777, tantos quebraderos de cabeza por 3 numeritos... :S
Gracias otra vez :D
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 15:38.