要求:做一个缩略图上传页面,上传完成,在页面显示缩略图,点击缩略图能看到
原来的大图片。

解决方案 »

  1.   

    为嘛不用div+css直接控制
    <div>
       <img style="width:100px; height:auto;" onclick="this.style.width='auto';"  src="food.jpg"  />
    </div>
      

  2.   

    div这个我很熟悉,不过现在学的是GD库,所以要用GD库做缩略图!!原因你懂的,帮帮忙吧!!先谢啦!!哈哈
      

  3.   


    <?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