php > 根据远程图片url 生成缩略图
$dw){ $par=$dw/$width; $width=$dw; $height=$height*$par; if($height>$dh){ $par=$dh/$height; $height=$dh; $width=$width*$par; } } elseif($height>$dh) { $par=$dh/$height; $height=$dh; $width=$width*$par; if($width>$dw){ $par=$dw/$width; $width=$dw; $height=$height*$par; } } else { $width=$width; $height=$height; } $nimg =imagecreatetruecolor($width,$height);// 新建一个真彩色画布 imagecopyresampled($nimg,$img,0,0,0,0,$width,$height,$w,$h);// 重采样拷贝部分图像并调整大小 imagejpeg($nimg,$image);// 以jpeg格式将图像输出到浏览器或文件 return true; } else {// 如果是执行生成缩略图操作则 $w=imagesx($img); $h=imagesy($img); $width = $w; $height = $h; $nimg =imagecreatetruecolor($dw,$dh); if($h/$w>$dh/$dw){// 高比较大 $width=$dw; $height=$h*$dw/$w; $intnh=$height-$dh; imagecopyresampled($nimg, $img, 0, -$intnh/1.8, 0, 0, $dw, $height, $w, $h); } else {// 宽比较大 $height=$dh; $width=$w*$dh/$h; $intnw=$width-$dw; imagecopyresampled($nimg, $img,-$intnw/1.8,0,0,0, $width, $dh, $w, $h); } imagejpeg($nimg,$image); return true; }};/** *根据url获取服务器上的图片 *$url服务器上图片路径 $filename文件名*/function grabimage($url,$filename=) { if($url==) return false; if($filename==) { $ext=strrchr($url,.); if($ext!=.gif && $ext!=.jpg && $ext!=.png) return false; $filename=date(ymdhis).$ext; } ob_start(); readfile($url); $img = ob_get_contents(); ob_end_clean(); $size = strlen($img); $fp2=@fopen($filename, a); fwrite($fp2,$img); fclose($fp2); return $filename;}?>
?
