| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- header("Content-Type: image/jpg");
- $image = imagecreatefromjpeg($_REQUEST['image']);
- $filename = $_REQUEST['image'];
- if ($_REQUEST['w']!='' && $_REQUEST['h']!='') {
- $thumb_width = $_REQUEST['w'];
- $thumb_height = $_REQUEST['h'];
- }
- else {
- $thumb_width = 400;
- $thumb_height = 400;
- }
- $width = imagesx($image);
- $height = imagesy($image);
- $original_aspect = $width / $height;
- $thumb_aspect = $thumb_width / $thumb_height;
- if ( $original_aspect >= $thumb_aspect ) {
- $new_height = $thumb_height;
- $new_width = $width / ($height / $thumb_height);
- }
- else {
- $new_width = $thumb_width;
- $new_height = $height / ($width / $thumb_width);
- }
- $thumb = imagecreatetruecolor( $thumb_width, $thumb_height );
- imagecopyresized($thumb,
- $image,
- 0 - ($new_width - $thumb_width) / 2,
- 0 - ($new_height - $thumb_height) / 2,
- 0, 0,
- $new_width, $new_height,
- $width, $height);
- imagejpeg($thumb,null,100);
|