Znalazłem coś w necie:
<?php
function rozszerzenie($file) {
$extension=$v[$n];
return $extension;
}
if (isset($_GET['link']) && isset($_GET['width']) && isset($_GET['height'])) { switch (rozszerzenie($_GET['link'])) {
case 'gif':
$img=imagecreatefromgif($_GET['link']);
$width=imagesx($img);
$height=imagesy($img);
$edit=false;
$valid[0]=true;
$valid[1]=true;
if ($width<=$_GET['width']) {
$valid[0]=false;
}
if ($height<=$_GET['height']) {
$valid[1]=false;
}
if ($width>$_GET['width']) {
$roznica=$width-$_GET['width'];
$wsp=$width/$roznica;
$nHeight=$height/$wsp;
$rHeight=$height-$nHeight;
$rWidth=$_GET['width'];
$edit=true;
}
if ($rHeight>$_GET['height']) {
$roznica=$rHeight-$_GET['height'];
$wsp=$rHeight/$roznica;
$nWidth=$rWidth/$wsp;
$rHeight=$_GET['height'];
$rWidth=$rWidth-$nWidth;
$edit=true;
}
if (!$edit && !$valid[0] && !$valid[1]) {
$rWidth=$width;
$rHeight=$height;
}
$img_mini=imagecreatetruecolor($rWidth,$rHeight);
imagecopyresampled($img_mini,$img,0,0,0,0,$rWidth,$rHeight,$width,$height);
header("Content-type: image/gif;"); imagegif($img_mini);
break;
case 'png':
$img=imagecreatefrompng($_GET['link']);
$width=imagesx($img);
$height=imagesy($img);
$edit=false;
$valid[0]=true;
$valid[1]=true;
if ($width<=$_GET['width']) {
$valid[0]=false;
}
if ($height<=$_GET['height']) {
$valid[1]=false;
}
if ($width>$_GET['width']) {
$roznica=$width-$_GET['width'];
$wsp=$width/$roznica;
$nHeight=$height/$wsp;
$rHeight=$height-$nHeight;
$rWidth=$_GET['width'];
$edit=true;
}
if ($rHeight>$_GET['height']) {
$roznica=$rHeight-$_GET['height'];
$wsp=$rHeight/$roznica;
$nWidth=$rWidth/$wsp;
$rHeight=$_GET['height'];
$rWidth=$rWidth-$nWidth;
$edit=true;
}
if (!$edit && !$valid[0] && !$valid[1]) {
$rWidth=$width;
$rHeight=$height;
}
$img_mini=imagecreatetruecolor($rWidth,$rHeight);
imagecopyresampled($img_mini,$img,0,0,0,0,$rWidth,$rHeight,$width,$height);
header("Content-type: image/png;"); imagepng($img_mini);
break;
case 'jpg':
$img=imagecreatefromjpeg($_GET['link']);
$width=imagesx($img);
$height=imagesy($img);
$edit=false;
$valid[0]=true;
$valid[1]=true;
if ($width<=$_GET['width']) {
$valid[0]=false;
}
if ($height<=$_GET['height']) {
$valid[1]=false;
}
if ($width>$_GET['width']) {
$roznica=$width-$_GET['width'];
$wsp=$width/$roznica;
$nHeight=$height/$wsp;
$rHeight=$height-$nHeight;
$rWidth=$_GET['width'];
$edit=true;
}
if ($rHeight>$_GET['height']) {
$roznica=$rHeight-$_GET['height'];
$wsp=$rHeight/$roznica;
$nWidth=$rWidth/$wsp;
$rHeight=$_GET['height'];
$rWidth=$rWidth-$nWidth;
$edit=true;
}
if (!$edit && !$valid[0] && !$valid[1]) {
$rWidth=$width;
$rHeight=$height;
}
$img_mini=imagecreatetruecolor($rWidth,$rHeight);
imagecopyresampled($img_mini,$img,0,0,0,0,$rWidth,$rHeight,$width,$height);
header("Content-type: image/jpeg;"); imagejpeg($img_mini);
break;
case 'jpeg':
$img=imagecreatefromjpeg($_GET['link']);
$width=imagesx($img);
$height=imagesy($img);
$edit=false;
$valid[0]=true;
$valid[1]=true;
if ($width<=$_GET['width']) {
$valid[0]=false;
}
if ($height<=$_GET['height']) {
$valid[1]=false;
}
if ($width>$_GET['width']) {
$roznica=$width-$_GET['width'];
$wsp=$width/$roznica;
$nHeight=$height/$wsp;
$rHeight=$height-$nHeight;
$rWidth=$_GET['width'];
$edit=true;
}
if ($rHeight>$_GET['height']) {
$roznica=$rHeight-$_GET['height'];
$wsp=$rHeight/$roznica;
$nWidth=$rWidth/$wsp;
$rHeight=$_GET['height'];
$rWidth=$rWidth-$nWidth;
$edit=true;
}
if (!$edit && !$valid[0] && !$valid[1]) {
$rWidth=$width;
$rHeight=$height;
}
$img_mini=imagecreatetruecolor($rWidth,$rHeight);
imagecopyresampled($img_mini,$img,0,0,0,0,$rWidth,$rHeight,$width,$height);
header("Content-type: image/jpeg;"); imagejpeg($img_mini);
break;
}
}
?>
Nie wiem czy działa, nie testowałem.