How to create a thumbnail from a larger image without losing quality? In Int looked - there are some Talmud written. Although it’s kind of done in a couple of lines ...
- one> In Inte looked - there are some Talmud written. Although it seems to be done in a couple of lines ... Talmuds do exist, but a really good script does not take a couple of lines at all. Let's clarify what should be the implementation? Those. The image should create a smaller copy when it is uploaded to the server, or is the image already on the server and you just need to reduce it and display it? - Palmervan
|
2 answers
Without loss of quality - a loose concept in this case, because when compressed, the quality will somehow be lost.
<?php function sharpen_image($img) { $filter = array ( array( 0, -1, 0), array(-1, 9, -1), array( 0, -1, 0), ); $divisor = array_sum(array_map('array_sum', $filter)); if (!imageconvolution($img, $filter, $divisor, 0)) return false; else return $img; } //максимальные ширина и высота: $width = 200; $height = 200; list($width_orig, $height_orig) = getimagesize("image.jpg"); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg("image.jpg"); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); sharpen_image($image_p);//можно обойтись без шарпинга imagejpeg($image_p, "image_preview.jpg", 100);//качество от 1 до 100 //если есть желание выдавать прямо в браузер, то до этой строчки вставляем //соответствующий хедер: header("Content-Type: image/jpeg"); //и меняем второй аргумент на null: imagejpeg($image_p, null, 100); ?>
|
ImageMagic can do it
- I'm talking about something else. - new_russian_man
|