Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/04/2009, 08:18
Avatar de Freakme
Freakme
 
Fecha de Ingreso: julio-2007
Ubicación: Portugalete
Mensajes: 97
Antigüedad: 16 años, 9 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