Mega Code Archive
Image Thumb
$MAX_WIDTH && $src_size[1] > $MAX_HEIGHT ) {
if ( $src_size[0] > $src_size[1] ) {
$dest_width = $MAX_WIDTH;
$dest_height = ( $src_size[1] * $MAX_WIDTH ) / $src_size[0];
}
else {
$dest_width = ( $src_size[0] * $MAX_HEIGHT ) / $src_size[1];
$dest_height = $MAX_HEIGHT;
}
}
else if ( $src_size[0] > $MAX_WIDTH ) {
$dest_width = $MAX_WIDTH;
$dest_height = ( $src_size[1] * $MAX_WIDTH ) / $src_size[0];
}
else if ( $src_size[1] > $MAX_HEIGHT ) {
$dest_width = ( $src_size[0] * $MAX_HEIGHT ) / $src_size[1];
$dest_height = $MAX_HEIGHT;
}
else {
$dest_width = $src_size[0];
$dest_height = $src_size[1];
}
if ( extension_loaded( 'gd' ) ) {
/* check the source file format */
$ext = substr( $_GET['s'], strrpos( $_GET['s'], '.' ) + 1 );
if ( $ext == 'jpg' || $ext == 'jpeg' ) $src = imagecreatefromjpeg( $_GET['s'] ) or die( 'Cannot load input JPEG image' );
else if ( $ext == 'gif' ) $src = imagecreatefromgif( $_GET['s'] ) or die( 'Cannot load input GIF image' );
else if ( $ext == 'png' ) $src = imagecreatefrompng( $_GET['s'] ) or die( 'Cannot load input PNG image' );
else die( 'Unsupported source file format' );
/* create and output the destination image */
$dest = imagecreate( $dest_width, $dest_height ) or die( 'Cannot initialize new GD image stream' );
imagecopyresized( $dest, $src, 0, 0, 0, 0, $dest_width, $dest_height, $src_size[0], $src_size[1] );
if ( imagetypes() & IMG_PNG ) {
header ( 'Content-type: image/png' );
imagepng( $dest );
}
else if ( imagetypes() & IMG_JPG ) {
header ( 'Content-type: image/jpeg' );
imagejpeg( $dest );
}
else if ( imagetypes() & IMG_GIF ) {
header ( 'Content-type: image/gif' );
imagegif( $dest );
}
else print 'Cannot find a suitable output format';
}
else print 'GD-library support is not available';
/* end buffered output */
ob_end_flush();
?>