当前位置:Gxlcms > PHP教程 > 如何在下载图片的PHP里添加上自动缩略图

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

时间:2021-07-01 10:21:17 帮助过:3人阅读

这段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."已存在
"); //文件存在 //exit('s:'.filesize($yname)); } else { echo($yname."
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('
'.$sqltext); $empire->query($sqltext); sleep(1); echo""; } else { //echo""; echo"完成"; } db_close(); $empire=null;

回复内容:

这段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."已存在
"); //文件存在 //exit('s:'.filesize($yname)); } else { echo($yname."
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('
'.$sqltext); $empire->query($sqltext); sleep(1); echo""; } else { //echo""; echo"完成"; } db_close(); $empire=null;

这不是帝国CMS么,你的需求应该是把远程图片保存下来的同时自动等比例裁剪,那就写个函数加到WriteFiletext_n里面就行了。至于怎么裁剪图片谷歌一下,可以直接用imagecopyresampled,或者安装了ImageMagick更好,这个比GD类库好使。

人气教程排行