<?php
/*=============================================
Drop-In Photo Gallery
Version 0.8
by Sam Perkins-Harbin
[URL unfurl="true"]www.forge22.com[/URL]
Last Revision: 12 February, 2006
=============================================*/
$image = $_GET['i'];
$max_width = $_GET['w'];
$max_height = $_GET['h'];
$pic = $_GET['p'];
$picture_location = $image;
$picture_save = str_replace($image, array(".jpg", ".gif", ".png"), ".temp");
$im_size = GetImageSize ( $picture_location);
$imageWidth = $im_size[0];
$imageHeight = $im_size[1];
if (eregi('.jpg', $picture_location)) { //If file is a JPG
$im2 = ImageCreateFromJPEG($picture_location);
} elseif (eregi('.gif', $picture_location)) { //If file is a GIF
$im2 = ImageCreateFromGIF($picture_location);
} elseif (eregi('.png', $picture_location)) { //If file is a PNG
$im2 = ImageCreateFromPNG($picture_location);
}
$x_ratio = $max_width / $imageWidth;
$y_ratio = $max_height / $imageHeight;
if ( ($imageWidth <= $max_width) || ($imageHeight <= $max_height) ) {
$tn_width = $imageWidth;
$tn_height = $imageWeight;
}
if (($x_ratio * $imageHeight) < $max_height) {
$tn_height = ceil($x_ratio * $imageHeight);
$tn_width = $max_width;
}
else {
$tn_width = ceil($y_ratio * $imageWidth);
$tn_height = $max_height;
}
$im = imageCreateTrueColor( $tn_width, $tn_height );
ImageCopyResampled ($im,$im2, 0, 0, 0, 0, $tn_width, $tn_height,$imageWidth, $imageHeight);
if (eregi('.jpg', $picture_location)) { //If file is a JPG
Header("Content-type: image/jpeg");
Imagejpeg($im,'',100); //to print to screen
Imagejpeg($im,$picture_save,100);
} elseif (eregi('.gif', $picture_location)) { //If file is a GIF
Header("Contrnt-type: image/gif");
Imagegif($im,'',100);
Imagegif($im,$picture_save,100);
} elseif (eregi('.png', $picture_location)) { //If file is a PNG
Header("Content-type: image/png");
Imagepng($im,'',100);
Imagepng($im,$picture_save,100);
}
[red]
$fh = fopen("../mytests/thumbs/$pic", "wb");
fwrite ($fh, $im2);
fclose ($fh);
[/red]
ImageDestroy($im);
ImageDestroy ($im2);
?>