<?php
header('Content-type: image/jpeg');
$file = "ftp/".basename(@$_GET['cam']).".jpg";
if (!file_exists($file)) {
	die();
}
$source = imagecreatefromjpeg($file);
$src_x = imagesx($source);
$src_y = imagesy($source);
$src_ratio = $src_x / $src_y;

$dst_x = 400;
$dst_y = 300;
$dst_ratio = $dst_x / $dst_y;
$correction = $dst_ratio / $src_ratio;
if ( $correction < 1 ) {
	$dst_y = $dst_y * $correction;
} elseif ($correction > 1) {
	$dst_x = $dst_x / $correction;
}

$resize = imagecreatetruecolor($dst_x, $dst_y);
imagecopyresampled($resize, $source, 0, 0, 0, 0, $dst_x, $dst_y, $src_x, $src_y);
imagejpeg($resize);

