Teniendo en cuenta que usted quiere hacer una imagen en miniatura y guardarlo, se podría aplicar un práctico cambiar el tamaño de la función como la siguiente:
<?php
function resize($sourcefile, $endfile, $thumbwidth, $thumbheight, $quality){
$ext1 = explode(".",trim($sourcefile));
$ext = strtolower(trim(array_slice($sext1,-1)));
switch($ext):
case 'jpg' or 'jpeg':
$img = imagecreatefromjpeg($sourcefile);
break;
case 'gif':
$img = imagecreatefromgif($sourcefile);
break;
case 'png':
$img = imagecreatefrompng($sourcefile);
break;
endswitch;
$width = imagesx($img);
$height = imagesy($img);
if ($width > $height) {
$newwidth = $thumbwidth;
$divisor = $width/$thumbwidth;
$newheight = floor($height/$divisor);
}
else {
$newheight = $thumbheight;
$divisor = $height/$thumbheight;
$newwidth = floor($width/$divisor);
}
// Create a new temporary image.
$tmpimg = imagecreatetruecolor($newwidth, $newheight);
// Copy and resize old image into new image.
imagecopyresampled($tmpimg, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Save thumbnail into a file.
switch($ext):
case 'jpg' or 'jpeg':
$makeimg = imagejpeg($tmpimg, $endfile, $quality);
break;
case 'gif':
$makeimg = imagegif($tmpimg, $endfile, $quality);
break;
case 'png':
$makeimg = imagepng($tmpimg, $endfile, $quality);
break;
endswitch;
// release the memory
imagedestroy($tmpimg);
imagedestroy($img);
if($makeimg){
chmod($endfile,0755);
return true;
}else{
return false;
}
}
?>
Luego, después de haber copiado t que el archivo a su servidor usando uno de mis métodos en mi respuesta anterior esto, se podía aplicar simplemente la función de la siguiente manera:
$doresize = resize($sourcefile, $endfile, $thumbwidth, $thumbheight, $quality);
echo ($doresize == true ? "IT WORKED" : "IT FAILED");
Esta función me sirve bastante bien. Lo aplico a miles de imágenes al día y funciona como un encanto.
¿Tiene permiso para establecer este parámetro ini? ¿Y esta advertencia está causando que la secuencia de comandos finalice? – SimonDowdles
BTW, ¿solo desea mostrar esta imagen, o realmente desea copiarla a su servidor? – SimonDowdles
No recibo ninguna advertencia sobre la configuración del archivo INI, sigue siendo un error fatal en la función gdcreate. – Dave