|
<? Php
Function imageResizer ($ url, $ width, $ height ){
Header ('content-type: image/jpeg ');
List ($ width_orig, $ height_orig) = getimagesize ($ url );
$ Ratio_orig = $ width_orig/$ height_orig;
If ($ width/$ height> $ ratio_orig ){
$ Width = $ height * $ ratio_orig;
} Else {
$ Height = $ width/$ ratio_orig;
}
// This resamples the image
$ Image_p = imagecreatetruecolor ($ width, $ height );
$ Image = imagecreatefromjpeg ($ url );
Imagecopyresampled ($ image_p, $ image, 0, 0, 0, 0, $ width, $ height, $ width_orig, $ height_orig );
// Output the image
Imagejpeg ($ image_p, null, 100 );
}
// Works with both POST and GET
$ Method = $ _ SERVER ['request _ method'];
If ($ method = 'get '){
ImageResize ($ _ GET ['url'], $ _ GET ['W'], $ _ GET ['H']);
} Elseif ($ method = 'post '){
ImageResize ($ _ POST ['url'], $ _ POST ['W'], $ _ POST ['H']);
}
// Makes the process simpler
Function loadImage ($ url, $ width, $ height ){
Echo 'image. php? Url = ', urlencode ($ url ),
'& W =', $ width,
'& H =', $ height;
}
?>
|