用GD库做缩略图 要求:做一个缩略图上传页面,上传完成,在页面显示缩略图,点击缩略图能看到原来的大图片。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 为嘛不用div+css直接控制<div> <img style="width:100px; height:auto;" onclick="this.style.width='auto';" src="food.jpg" /></div> div这个我很熟悉,不过现在学的是GD库,所以要用GD库做缩略图!!原因你懂的,帮帮忙吧!!先谢啦!!哈哈 <?phpheader('Content-type: image/jpeg');$filename = 'food.jpg';$maxSize = 200; // 缩略图最大高度或宽度// 读取源图像$source = imagecreatefromjpeg($filename);// 源图像的宽和高$width = imagesx( $source );$height = imagesy( $source );// 设置缩略图的大小if( $width >= $height ){ $newWidth = $maxSize; $newHeight = (int)( $height * ( $maxSize/$width ));}else{ $newHeight = $maxSize; $newWidth = (int)( $width * ( $maxSize/$height ) );}// 创建缩略图$thumb = imagecreatetruecolor($newWidth, $newHeight);// 拷贝 $source 并到 $thumb imagecopyresampled( $thumb, $source, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);// Outputimagejpeg($thumb);?>手册上的例子 http://www.php.net/manual/zh/function.imagecopyresampled.php 【php 包含头文件问题】 如何学好PHP 链接问题 关于脚本php,与javascript的优劣? 关于php操作数据库 数据修改成功后,页面显示的还是原来的数据 推荐几个优秀的源码下载站点,有好的一起顶! PHP中如何实现像JSP中forward的功能 如何实现在表单提交后,仍然保持菜单项上一次的状态,急急。在线等 Any PHP shopping cart for sales? 用什么样的方法能最简单的切分这样的字符串 ckeditor 换行问题
<div>
<img style="width:100px; height:auto;" onclick="this.style.width='auto';" src="food.jpg" />
</div>
<?php
header('Content-type: image/jpeg');$filename = 'food.jpg';
$maxSize = 200; // 缩略图最大高度或宽度// 读取源图像
$source = imagecreatefromjpeg($filename);// 源图像的宽和高
$width = imagesx( $source );
$height = imagesy( $source );// 设置缩略图的大小
if( $width >= $height ){
$newWidth = $maxSize;
$newHeight = (int)( $height * ( $maxSize/$width ));
}
else{
$newHeight = $maxSize;
$newWidth = (int)( $width * ( $maxSize/$height ) );
}// 创建缩略图
$thumb = imagecreatetruecolor($newWidth, $newHeight);
// 拷贝 $source 并到 $thumb
imagecopyresampled( $thumb, $source, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
// Output
imagejpeg($thumb);
?>手册上的例子 http://www.php.net/manual/zh/function.imagecopyresampled.php