creating thumbnails without saving them

别等时光非礼了梦想. 提交于 2019-12-13 00:07:27

问题


I need to create a page that will automatically create a thumbnail from all images if selected folder and show them on the same page. But the thing is, I don't want to save them. I want to display them on the same page without saving. And I need to do that in PHP. Is it possible? Please help! Note: If that is not possible,I can put them in some folder.


回答1:


You have to make a second PHP-file then. You have to make an image tag in the first file <img src='image.php' /> and in this image.php you have to print out the image like:

header("Content-type: image/png");

$im     = imagecreatefrompng("image.png");
list($width, $height) = getimagesize($im);
$newimage = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($newimage, $im, 0, 0, 0, 0, "100", "100", $width, $height);

imagepng($newimage);
imagedestroy($newimage);
imagedestroy($im);



回答2:


You might also consider using data URIs. Use the code in DRP96's answer to create the thumbnail, but instead of doing it in a separate PHP and requiring many image requests, embed the images directly on the page.

Most modern browsers support data URIs now, but as usual, watch out for IE.




回答3:


replace this line

list($width, $height) = getimagesize($im);

with this

list($width, $height) = getimagesize("image.png");


来源:https://stackoverflow.com/questions/9841714/creating-thumbnails-without-saving-them

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!