num_rows == 0) { exit("ERROR: PartId not found!"); } $source_path = $GlobalPictureDir . "/" . $db_result->fetch_array()['PicturePath']; // get image info list($source_width, $source_height) = getimagesize($source_path); $mime_type = mime_content_type($source_path); // calculate new With and Height $output_width = $source_width; $output_height = $source_height; $max_width = 0; if (isset($_GET['MaxWidth'])) { $max_width = intval($_GET['MaxWidth']); if ($output_width > $max_width) { $scale_factor = $max_width / $output_width; $output_width *= $scale_factor; $output_height *= $scale_factor; } } $max_height = 0; if (isset($_GET['MaxHeight'])) { $max_height = intval($_GET['MaxHeight']); if ($output_height > $max_height) { $scale_factor = $max_height / $output_height; $output_width *= $scale_factor; $output_height *= $scale_factor; } } // load image if ($mime_type == 'image/jpeg') { $source_image = imagecreatefromjpeg($source_path); $output_image = imagecreatetruecolor($output_width, $output_height); } else if ($mime_type == 'image/png') { $source_image = imagecreatefrompng($source_path); imagealphablending($source_image, true); imagesavealpha($source_image, true); $output_image = imagecreate($output_width, $output_height); } else { ErrorLog("Unkown mime type: " . $mime_type . "!"); exit("Can't handle requested mime-type."); } // resize $res = imagecopyresized($output_image, $source_image, 0, 0, 0, 0, $output_width, $output_height, $source_width, $source_height); if ($res !== True) { $msg = "Cannot resize image: " . $source_path . "\n"; $msg .= "source: " . $source_width . "x" . $source_height; $msg .= ", max: " . $max_width . "x" . $max_height; $msg .= ", output: " . $output_width . "x" . $output_height; ErrorLog($msg); exit("Cannot resize image!"); } // output as png header('Content-Type: image/png'); imagepng($output_image); imagedestroy($output_image); imagedestroy($source_width); ?>