How to create a smaller copy of the downloaded image in php? Maybe there is something more convenient than php?

  • 2
    yes, photoshop :) - Artem
  • Aha, all users would be so conscious, then there would be no problems)) - glarionenko
  • yes <img src="img.jpg" width="100" /> do not specify the height! But at the same time the weight will be oreginlen) - Palmervan
  • That's why I'm looking for a solution, because I want to save user traffic - glarionenko

1 answer 1

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); ?>