求读取图片缩略成指定的宽如 a.php
   1.jpg  这个图片数300px 300px的高宽通过a.php读图片后宽50px;但没有改变1.jpg的高宽300px 300px只是显示出宽50px而已;并没有生成到服务器
就是只读显示不生成。

解决方案 »

  1.   

    <img src="a.php?img=1.jpg" />a.php(以下代码来自PHP手册拼接)
    =====
    <?php
    // File and new size
    $filename = empty($_GET['img'])?"default.jpg":trim($_GET['img']);// Content type
    header('Content-type: image/jpeg');// Get new sizes
    list($width, $height) = getimagesize($filename);
    $newwidth = 300;
    $newheight = 300;// Load
    $thumb = imagecreatetruecolor($newwidth, $newheight);
    $source = imagecreatefromjpeg($filename);// Resize
    imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);// Output
    imagejpeg($thumb);
    ?>