Du kunne bruge noget i denne stil:
<?php
//http://www.exp.dk/spm/672864
function LoadJpeg($imgname)
{
$im = @imagecreatefromjpeg($imgname); /* Attempt to open */
if (!$im)
{
/* See if it failed */
$im = imagecreate(150, 30); /* Create a blank image */
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
/* Output an errmsg */
imagestring($im, 1, 5, 5, "Error loading $imgname", $tc);
}
return $im;
}
$file = $_GET['file'];
$maxw = 100;
$maxh = 100;
header("Content-type: image/jpeg");
$srcim = LoadJpeg($file);
$ow = imagesx( $srcim );
$oh = imagesy( $srcim );
$wscale = $maxw / $ow;
$hscale = $maxh / $oh;
$scale = ( $hscale < $wscale ? $hscale : $wscale );
$nw = round( $ow * $scale, 0 );
$nh = round( $oh * $scale, 0 );
$dstim = imagecreatetruecolor( $nw, $nh );
imagecopyresampled( $dstim, $srcim, 0, 0, 0, 0, $nw, $nh, $ow, $oh );
imagejpeg( $dstim );
imagedestroy( $dstim );
imagedestroy( $srcim );
?>
Du kan se koden i aktion på siden:
http://www.codebreaker.dk/exp/672864.php?file=(et fuldt link til et jpg/jpeg billede)