这是我用来调整站点中图像大小的脚本。但是我不知道如何添加功能来保存该图像的缩略图。如果我可以保存缩略图,则可以稍后再使用该缩略图,而不必一次又一次地使用此脚本。
<?php
$time=time();
$neww = 65;
$newh = 87;
$file=htmlspecialchars($_GET['file']);
list(, , $type,)=getimagesize($file);
if($type==1) {
$funci='imagecreatefromgif';
} //$funco='imagegif';}
if($type==2) {
$funci='imagecreatefromjpeg';
} //$funco='imagejpeg';}
if($type==3) {
$funci='imagecreatefrompng';
} //$funco='imagepng';}
if($type) {
$im1 = $funci($file);
$im2=imagecreatetruecolor($neww,$newh);
imagecopyresized($im2, $im1, 0,0,0,0,$neww,$newh, imagesx($im1), imagesy($im1));
header('Content-type: image/gif');
imagegif($im2);
}
?>
imagegif
如果将要保存到的文件的位置作为第二个参数传递给该函数,则已经为您完成了该操作。
imagegif($im2); //output raw image stream directly
imagegif($im2, 'path/to/image_save.gif'); //saves to the file at mentioned path
但是,必须注意,如果path/to/image_save.gif
已经存在,它将被覆盖。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句