按比例生成缩略图的代码

时间:2007-08-12 22:43:18   来源:  作者:  点击:次  出处:技术无忧
关键字:缩略图 gd 代码 php

<?php
#########################################################
#                                                       #
# Release....: ImageVue.v1.4.PHP.NULL-WDYL              #
# Date.......: 01/30/04                                 #
# Released...: WDYL                                     #
# Protection.: CallHome, License Check, Refferer Links  #
# URL........: http://www.imagevuex.com                 #
#                                                       #
#########################################################
$img=$_GET['img'];
$path = substr($img, 0, strrpos($img, '/'));
$file = substr($img, strrpos($img, '/') + 1);

$tnpath = $path . '/tn_' . $file;

if (@file_exists($tnpath)) {
    Header("Content-type: image/jpeg");
    readfile($tnpath);

} elseif (!file_exists($img)) {
    die("Image doesn't exist");

} else {
    if (function_exists("imagecreatefromjpeg") and function_exists("imagecreatetruecolor")) {
        $orig_image = imagecreatefromjpeg($img);
        $orig_x = imagesx($orig_image);
        $orig_y = imagesy($orig_image);

        if (($orig_x / $orig_y) >= (4 / 3)) {
            $y = round($orig_y / ($orig_x / 158));
            $x = 158;
        } else {
            $x = round($orig_x / ($orig_y / 118));
            $y = 118;
        }

        $sm_image = imagecreatetruecolor($x, $y);
        Imagecopyresampled($sm_image, $orig_image, 0, 0, 0, 0, $x, $y, $orig_x, $orig_y);
        Header("Content-type: image/jpeg");
        imageJPEG($sm_image, '', 80);
        @imageJPEG($sm_image, $tnpath, 80);
        imagedestroy ($sm_image);
        imagedestroy ($orig_image);
    } else {

        header("Content-type: image/jpeg");
        readfile ('thumb.jpg');
    }
}
?>

欢迎收藏Pc51.Net技术无忧网


文章评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面