How to create a smaller copy of the downloaded image in php? Maybe there is something more convenient than php?
|
1 answer
This is a typical task. Solved using imagecopyresized (GD). Example from the manual:
<?php // Имя файла и масштаб $filename = 'test.jpg'; $percent = 0.5; // Тип содержимого header('Content-Type: image/jpeg'); // Получение новых размеров list($width, $height) = getimagesize($filename); $newwidth = $width * $percent; $newheight = $height * $percent; // Загрузка $thumb = imagecreatetruecolor($newwidth, $newheight); $source = imagecreatefromjpeg($filename); // Масштабирование imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); // Вывод imagejpeg($thumb); ?>
|
<img src="img.jpg" width="100" />
do not specify the height! But at the same time the weight will be oreginlen) - Palmervan