11.jpg
水印图
执行该脚本之后,生成的缩略图没问题,正常保存
但是页面却显示小边框
求解,谢谢诸位
回复内容: watermark=./logo.jpg; } // $imageinfo是上传图片后返回的信息 // $type - 1代表生成商品或文章的缩略图,2代表生成头像缩略图 public function makethumb($imageinfo,$with=360,$height=360,$type=1){ if($imageinfo['type']==.jpg){ $src_image=imagecreatefromjpeg($imageinfo['source_img_path']); }else if($imageinfo['type']==.png){ $src_image=imagecreatefrompng($imageinfo['source_img_path']); }else if($imageinfo['type']==.gif){ $src_image=imagecreatefromgif($imageinfo['source_img_path']); } $image=imagecreatetruecolor($with,$height); $white=imagecolorallocate($image,255,255,255); // 将背景设为透明 imagecolortransparent($image,$white); imagefill($image,0,0,$white); // 开始判断最终生成的缩略图尺寸,避免变形 $finalwidth=$with; $finalheight=$height; $x=$y=0; if($imageinfo['width']$imageinfo['height']){ // 确定缩放比例 $scale=round($finalwidth/$imageinfo['width'],2); $finalheight=round($scale*$imageinfo['height']); $y=round(($height-$finalheight)/2); }else if($imageinfo['width']$height){ $scale=round($finalheight/$imageinfo['height'],2); $finalwidth=round($scale*$imageinfo['width']); $x=round(($with-$finalwidth)/2); }else if($with=200 && $finalheight>=260){ $watermark=imagecreatefromjpeg($this->watermark); imagecopymerge($image,$watermark,$finalwidth-100,$finalheight-130,0,0,100,130,80); imagedestroy($watermark); } !is_dir($this->thumbpath) && mkdir($this->thumbpath); // 保存路径+名字 $this->thumbpath=$this->thumbpath./.time().mt_rand()._{$finalwidth}_{$finalheight}.png; // 最后统一生成png格式,清晰度较高 header(content-type:image/png); imagepng($image,$this->thumbpath); imagedestroy($image); imagedestroy($src_image); }}if($_files){ $a=new thumb(); // 实际图片信息是上传处理过的信息,这里写成了固定的 $a->makethumb(array('width'=>430,'height'=>430,'type'=>'.jpg','source_img_path'=>'./11.jpg'));}?>
11.jpg
水印图
执行该脚本之后,生成的缩略图没问题,正常保存
但是页面却显示小边框
求解,谢谢诸位
header(content-type:image/png); 把这一段删除试试?
你只是生成缩略图并不直接把缩略图显示给浏览器,却配置了浏览器输出为png格式,显示个方块,就是浏览器要显示图片,但是却没有正确的图片显示。
