Home >Backend Development >PHP Tutorial > php打造缩略图图片

php打造缩略图图片

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 13:17:22762browse

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>


">
Statement:
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