如何在下载图片的PHP里添加上自动缩略图

这段PHP本来是把titlepic里的外链图片自动下载,我想让它在下载时自动缩略成固定大小的图片。求教应该怎么修改呢?

    $sqltext="SELECT id,titlepic FROM {$dbtbpre}_article where titlepic like 'http://%' order by id limit 1";
    $r=$empire->fetch1($sqltext);
    if($r)
    {
        $path=ECMS_PATH."uploads\\pic\\";
        $yname=$path.basename($r[titlepic]);
        $filename='/uploads/pic/'.basename($r[titlepic]);

        if(file_exists($yname)&&filesize($yname)>0)
        {
            echo($yname."已存在<br>");  //文件存在 
            //exit('s:'.filesize($yname));
        }
        else
        {
            echo($yname."<br>down:".$r[titlepic]);

            $string=ReadFiletext($r[titlepic]);
            WriteFiletext_n($yname,$string);
            sleep(1);           
        }
        $sqltext="update {$dbtbpre}_article set titlepic='$filename' where id='$r[id]'";
        echo('<br>'.$sqltext);
        $empire->query($sqltext);
        sleep(1);   
        echo"<meta http-equiv=\"refresh\" content=\"1;url=?act\">";
    }
    else
    {
        //echo"<meta http-equiv=\"refresh\" content=\"1;url=ListAllInfo.php\">";
        echo"完成";
    }
    db_close();
    $empire=null;
查看回复