Files

34 lines
861 B
PHP

<?php
$file = 'kuva1.jpg';
list($old_width, $old_height) = getimagesize($file);
$max_width = 400;
if ($old_width > $max_width) {
$ratio = $old_width / $max_width;
$new_width = $max_width;
$new_height = (int) round($old_height / $ratio);
} else {
$new_width = $old_width;
$new_height = $old_height;
}
//echo "New dimensions: {$new_width} x {$new_height}";
$new_image = imagecreatetruecolor($new_width, $new_height);
$old_image = imagecreatefromjpeg($file);
imagecopyresampled($new_image, $old_image, 0, 0, 0, 0, $new_width, $new_height, $old_width, $old_height);
// Tell the browser this script returns a JPEG image
header('Content-Type: image/jpeg');
// Output the image stream directly to the browser
imagejpeg($new_image, null, 90); // 90 = quality percentage (0-100)
imagedestroy($old_image);
imagedestroy($new_image);