I have this code:
<?php
// The file
$filename = 'http://www.tagesschau.de/multimedia/bilder/feinstaub-messstation-101.jpg';
$new_width = 400;
$new_height = 200;
// Content type
header('Content-type: image/jpeg');
// Get new dimensions
list($width, $height) = getimagesize($filename);
// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Output
imagejpeg($image_p, null, 100);
?>
When calling this script it'll show the image http://www.tagesschau.de/multimedia/bilder/feinstaub-messstation-101.jpg
but resize the image before: 400 x 200.
You can declare width and height with the values in $new_width
and $new_height
. I need to specify width and height.
What I want to reach: I want to only declare width. Height should adapt dynamically proportional to the original dimensions. Is there a way to do this?