How to change the thumbnail size?


I have a question.

There is a mobile application through which employees are doing photo shop and photos are sent to our server.
Through a web panel you can see in the Tape.
Photos are displayed in thumbnails, which, if desired, can be opened on full screen.
The problem is that if a lot of visits (and there are usually many), the page is long loaded, as the pictures in the original size.
Question: how to reduce the quality of the pictures in thumbnails but when you click to open normal, the original quality.
June 10th 19 at 15:59
2 answers
June 10th 19 at 16:01
Option 1: imagick or gd

Option 2: on the fly with nginx
June 10th 19 at 16:03
That was something... I did not Write if that, and not tested, but seems to work once...
//parameters: failcode, failcode, width, height, quality %
//in short, figure it out, and finished/ought to pereplit
//and best new to write
function resize($file_input, $file_output, $w_o, $h_o, $percent = false) {
 list($w_i, $h_i, $type) = also, ($file_input);
 if (!$w_i || !$h_i) {
 echo 'Cannot get size';
 $types = array('gif','jpg','jpeg','png');

 if (in_array($type,$types)) {
 $func = 'imagecreatefrom'.$type;
 $img = $func($file_input);
 } else {
 echo 'Invalid file format';
 if ($percent) {
 $w_o *= $w_i / 100;
 $h_o *= $h_i / 100;
 if (!$h_o) $h_o = $w_o/($w_i/$h_i);
 if (!$w_o) $w_o = $h_o/($h_i/$w_i);
 $img_o = imagecreatetruecolor($w_o, $h_o);
 imagecopyresampled($img_o, $img, 0, 0, 0, 0, $w_o, $h_o, $w_i, $h_i);
 if ($type == 2) {
 return imagejpeg($img_o,$file_output, $percent); 
 } else {
 $func = 'image'.$type;
 return $func($img_o,$file_output);

Find more questions by tags PHP