用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 数据库没有反应 关于vss版本控制器! 请教怎样在网页中嵌入windows画图板功能?或者怎样实现类似画图板功能? 如何在操作数据库出错时不显示出错的信息 php5+mysql4读出的数据库记录为什么是乱码,如何解决.谢谢了. 在线等待 PHP连接sql sever的问题 想做一个CMS,请各位给点意见! 谁有PHP4操纵oracle8i的代码给小弟学习学习? 为什么在本地服务器能行,传到线上后台就不能用了? php 多表查询 指定值查 用什么样的方法能最简单的切分这样的字符串 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