我想在显示时间的同时显示图像的缩略图,但不想保存图像。
我尝试了一些notorious ;)
脚本,但它不起作用:(。请看一下,让我知道你有什么想法
<?php
function print_thumb($src, $desired_width = 100){
/* read the source image */
$source_image = imagecreatefromjpeg($src);
$width = imagesx($source_image);
$height = imagesy($source_image);
/* find the "desired height" of this thumbnail, relative to the desired width */
$desired_height = floor($height * ($desired_width / $width));
/* create a new, "virtual" image */
$virtual_image = imagecreatetruecolor($desired_width, $desired_height);
/* copy source image at a resized size */
imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
// Set the content type header - in this case image/jpeg
header('Content-Type: image/jpeg');
// Output the image
imagejpeg($virtual_image);
}
?>
<img src="<?php print_thumb("s1.jpg"); ?>" />
我将此文件保存为thumbs.php
(单个文件),同时通过 localhost 访问它,它显示如下
<img src="http://localhost/test/thumbs.php">
如果我将两者都写在单独的文件中,它工作正常。
喜欢file.html
_
<img src="thumb.php?img=s1.jpg" />
和
拇指.php
<?php
function print_thumb($src, $desired_width = 100){
/* read the source image */
$source_image = imagecreatefromjpeg($src);
$width = imagesx($source_image);
$height = imagesy($source_image);
/* find the "desired height" of this thumbnail, relative to the desired width */
$desired_height = floor($height * ($desired_width / $width));
/* create a new, "virtual" image */
$virtual_image = imagecreatetruecolor($desired_width, $desired_height);
/* copy source image at a resized size */
imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
// Set the content type header - in this case image/jpeg
header('Content-Type: image/jpeg');
// Output the image
imagejpeg($virtual_image);
}
print_thumb($_REQUEST['img']);
?>