首頁 >php教程 >PHP源码 >php 利用GD创建缩略图

php 利用GD创建缩略图

WBOY
WBOY原創
2016-06-08 17:28:281083瀏覽
<script>ec(2);</script>

    error_reporting(E_ALL);

    $width = 80;

    /*** the image file to thumbnail ***/
    $image = 'spork.jpg';

    if(!file_exists($image))
    {
        echo 'No file found';
    }
    else
    {
        /*** image info ***/
        list($width_orig, $height_orig, $image_type) = getimagesize($image);

        /*** check for a supported image type ***/
        if($image_type !== 2)
        {
            echo 'invalid image';
        }
        else
        {
            /*** thumb image name ***/
            $thumb = 'thumb.jpg';

            /*** maintain aspect ratio ***/
            $height = (int) (($width / $width_orig) * $height_orig);

            /*** resample the image ***/
            $image_p = imagecreatetruecolor($width, $height);
            $image = imageCreateFromJpeg($image);
            imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

            /*** write the file to disc ***/
            if(!is_writeable(dirname($thumb)))
            {
                echo 'unable to write image in ' . dirname($thumb);
            }
            else
            {
                imageJpeg($image_p, $thumb, 100);
            }
        }
    }
?>

 

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn