首页  >  文章  >  后端开发  >  php打造缩略图图片

php打造缩略图图片

WBOY
WBOY原创
2016-06-13 13:17:22714浏览

php制作缩略图图片

<?php if (! isset ( $_POST ["submit"] )) {
	echo "<?xml version=\"1.0\" encoding=\"UTF-8\"";
} else {
	if (isset ( $_FILES ["file"] ) || $_POST ["file"] != "") {
		function resizeimage($file, $rate = .5) {
			$size = getimagesize ( $file );
			switch ($size [2]) {
				case 1 :
					$img = imagecreatefromgif ( $file );
					break;
				case 2 :
					$img = imagecreatefromjpeg ( $file );
					break;
				case 3 :
					$img = imagecreatefrompng ( $file );
					break;
			}
			$srcw = imagesx ( $img );
			$srch = imagesy ( $img );
			$detw = floor ( $srcw * $rate );
			$deth = floor ( $srch * $rate );
			$im = imagecreatetruecolor ( $detw, $deth );
			$black = imagecolorallocate ( $im, 255, 255, 255 );
			imagefilledrectangle ( $im, 0, 0, $detw, $deth, $black );
			imagecopyresized ( $im, $img, 0, 0, 0, 0, $detw, $deth, $srcw, $srch );
			header ( 'Content-type:image/png' );
			imagepng ( $im );
			imagedestroy ( $im );
			imagedestroy ( $img );
		}
		resizeimage ( $_FILES ["file"] ["tmp_name"] );
	}
}
?>




<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
td {
	margin: 0;
}
</style>
<script type="text/javascript">
function submit(){
	obj=document.form1.submit();
	return obj;
}
</script>


">
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn