Home > php教程 > php手册 > body text

关于生成缩略图的问题,各位大侠请进来

WBOY
Release: 2016-06-21 09:14:02
Original
1199 people have browsed it

缩略图|问题

从网上找来了从jpg文件生成缩略图的程序,略加改动变成下面的程序,现在这个程序可以将一个jpg文件的缩略图直接输出,但我想在网页的某个位置插入一个或者多个缩略图以方便我编辑图片的时候有所依据,但下面的这个函数在输出的时候出现很多乱码,如何解决呢?

function makethumb($srcFile,$dstW,$dstH, $type='png') {
$data = GetImageSize($srcFile,&$info);
switch ($data[2]) {
case 1:
$im = ImageCreateFromGIF($srcFile);
break;
case 2:
$im = ImageCreateFromJPEG($srcFile);
break;
case 3:
$im = ImageCreateFromPNG($srcFile);
break;
}
$srcW=ImageSX($im);
$srcH=ImageSY($im);
$dstX=0;
$dstY=0;
if ($srcW*$dstH>$srcH*$dstW) {
$fdstH=round($srcH*$dstW/$srcW); $dstY=floor(($dstH-$fdstH)/2); $fdstW=$dstW;
} else {
$fdstW=round($srcW*$dstH/$srcH); $dstX=floor(($dstW-$fdstW)/2); $fdstH=$dstH;
}
$ni=imagecreate($dstW,$dstH);
$dstX=($dstX$dstY=($dstX$dstX=($dstX>($dstW/2))?floor($dstW/2):$dstX;
$dstY=($dstY>($dstH/2))?floor($dstH/s):$dstY;
$white = ImageColorAllocate($ni, 255,255,255);//Ìî³äµÄ±³¾°É«
imagefilledrectangle($ni,0,0,$dstW,$dstH,$white);
ImageCopyResized($ni,$im,$dstX,$dstY,0,0,$fdstW,$fdstH,$srcW,$srcH);
ImageJpeg($ni);
//imagedestroy($im);
//imagedestroy($ni);
}


makethumb("1.jpg",259,193,"jpg");



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!