<?php
//исходный файл 1920 * 1200, для примера
$file = $_GET['file'];
list($width, $height, $type) = getimagesize($file);
$slashPos = strrpos($file,'_');
$fileName = substr($file,$slashPos);
$fileName = str_replace("_", "1", $fileName);
$str="Content-Disposition: attachment; filename=".$fileName;
header($str);
header("Content-type: $type");
$new_height = 768;
$k = $height / $new_height;
$new_width = $width / $k;
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($file);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($image_p, null, 100);
$file = $image_p;
// создана картинка с заданной высотой, ширина чуток больше
$end_width = 1024;
$end_height = 768;
list($width2, $height2, $type) = getimagesize($file); // 1228 * 768
$slashPos = strrpos($file,'_');
$fileName = substr($file,$slashPos);
$fileName = str_replace("_", "1", $fileName);
$str="Content-Disposition: attachment; filename=".$fileName;
header($str);
header("Content-type: $type");
$razn = $width2 - $end_width; // 234 - разница между исходным и требуемым по ширине
$razn = $razn / 2; // 117 - разница в ширине с одной стороны
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($file);
imagecopyresampled($image_p, $image, 0, 0, $razn, 0, $end_width, $end_height, $width2, $height2);
imagejpeg($image_p, null, 80);
$file = $image_p;
$str="Content-Disposition: attachment; filename=".$fileName;
header($str);
header("Content-type: application/octet-stream");
echo file_get_contents($file);
?>