关于生成图片缩略图的神秘问题-_-!! gd1.6.2么有此问题,gd2多是这样。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 有必要生成缩略图吗??我一直是用<img src=***.jpg width=100>这样的,别说速度慢,当你点击看大图片时,由于图片已经载入,哪就快多了 有必要啊,象一些图片交易网站,没交钱只能看小图片,真实图片只能交钱之后才能看。呵呵偶在网上找的制作缩略图的一个函数,蛮好用,偶一直在用:// 本函数从源文件取出图象,设定成指定大小,并输出到目的文件 // 源文件格式:gif,jpg,jpe,jpeg,png // 目的文件格式:jpg // 参数说明: // $srcFile 源文件 // $dstFile 目标文件 // $dstW 目标图象宽度 // $dstH 目标图象高度 function makethumb($srcFile,$dstFile,$dstW,$dstH) { $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<0)?0:$dstX; $dstY=($dstX<0)?0:$dstY; $dstX=($dstX>($dstW/2))?floor($dstW/2):$dstX; $dstY=($dstY>($dstH/2))?floor($dstH/s):$dstY; $black = ImageColorAllocate($ni, 255,255,255);//填充的背景色你可以重新指定,我用的是黑色 imagefilledrectangle($ni,0,0,$dstW,$dstH,$black); ImageCopyResized($ni,$im,$dstX,$dstY,0,0,$fdstW,$fdstH,$srcW,$srcH); ImageJpeg($ni,$dstFile);//如果你要把图片直接输出到浏览器,那么把第二个参数去掉,并用header()函数指定mine类型先 imagedestroy($im); imagedestroy($ni); } 楼上可不可以举个例子,怎么用啊?多谢了.或者是给我email:jyc@[email protected] 那个目标文件是什么?// $dstFile 目标文件 function ResizeImage($image,$newname){ global $img_config;//配置变量array在你的配置文件中或者你也可以自己写。 $maxwidth = $img_config['resize_width'];//自己指定大小 $maxheight = $img_config['resize_height']; $name = $img_config['uploadpath'].$newname;//图片的存放路径 $width = imagesx($image); $height = imagesy($image); if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){ if($maxwidth && $width > $maxwidth){ $widthratio = $maxwidth/$width; $reWidth=true; } if($maxheight && $height > $maxheight){ $heightratio = $maxheight/$height; $reHeight=true; } if($reWidth && $reHeight){ if($widthratio < $heightratio){ $ratio = $widthratio; }else{ $ratio = $heightratio; } }elseif($reWidth){ $ratio = $widthratio; }elseif($reHeight){ $ratio = $heightratio; } $newwidth = $width * $ratio; $newheight = $height * $ratio; if(function_exists("imagecopyresampled")){ //this function needs GD 2.0.1 or later. $newim = imagecreatetruecolor($newwidth, $newheight); imagecopyresampled($newim, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); }else{ $newim = imagecreate($newwidth, $newheight); imagecopyresized($newim, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); } ImageJpeg ($newim,$name); ImageDestroy ($newim); }else{ ImageJpeg ($image,$name); }} 真的是gd库的版本问题.换了新的2.0反而没有以前的好用了.装回以前的后就解决了.^_^thank you 数据库插入新的字段出错 根据关键字搜索数据时,如何在执行sql语句时去掉字段中的html标签,再使用like去模糊查询?? 问一个很简单的PHP问题 这段for语句的执行什么意思 【求职】北京PHP软件开发工程师 这是怎么做的!! 关于自定义函数的 页面提交刷新问题 php+mysql+apache的通用安装整合方法(越详细越好) PHP,如何删除字符串中特殊子串 这个缩略图如何修改上传路径呢?? 谁有比较好的缩略图生成函数?
<img src=***.jpg width=100>
这样的,别说速度慢,当你点击看大图片时,由于图片已经载入,哪就快多了
// 源文件格式:gif,jpg,jpe,jpeg,png
// 目的文件格式:jpg
// 参数说明:
// $srcFile 源文件
// $dstFile 目标文件
// $dstW 目标图象宽度
// $dstH 目标图象高度
function makethumb($srcFile,$dstFile,$dstW,$dstH) {
$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<0)?0:$dstX;
$dstY=($dstX<0)?0:$dstY;
$dstX=($dstX>($dstW/2))?floor($dstW/2):$dstX;
$dstY=($dstY>($dstH/2))?floor($dstH/s):$dstY;
$black = ImageColorAllocate($ni, 255,255,255);//填充的背景色你可以重新指定,我用的是黑色
imagefilledrectangle($ni,0,0,$dstW,$dstH,$black);
ImageCopyResized($ni,$im,$dstX,$dstY,0,0,$fdstW,$fdstH,$srcW,$srcH);
ImageJpeg($ni,$dstFile);//如果你要把图片直接输出到浏览器,那么把第二个参数去掉,并用header()函数指定mine类型先
imagedestroy($im);
imagedestroy($ni);
}
{
global $img_config;//配置变量array在你的配置文件中或者你也可以自己写。 $maxwidth = $img_config['resize_width'];//自己指定大小
$maxheight = $img_config['resize_height'];
$name = $img_config['uploadpath'].$newname;//图片的存放路径
$width = imagesx($image);
$height = imagesy($image); if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){
if($maxwidth && $width > $maxwidth){
$widthratio = $maxwidth/$width;
$reWidth=true;
}
if($maxheight && $height > $maxheight){
$heightratio = $maxheight/$height;
$reHeight=true;
}
if($reWidth && $reHeight){
if($widthratio < $heightratio){
$ratio = $widthratio;
}else{
$ratio = $heightratio;
}
}elseif($reWidth){
$ratio = $widthratio;
}elseif($reHeight){
$ratio = $heightratio;
}
$newwidth = $width * $ratio;
$newheight = $height * $ratio; if(function_exists("imagecopyresampled")){ //this function needs GD 2.0.1 or later.
$newim = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($newim, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}else{
$newim = imagecreate($newwidth, $newheight);
imagecopyresized($newim, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}
ImageJpeg ($newim,$name);
ImageDestroy ($newim);
}else{
ImageJpeg ($image,$name);
}
}