• 按规定宽度等比压缩图片(压缩后图片的大小也会被压缩)



    $newWidth=600;

    $file_path='D:/myWorkspace/get_img/deal_img/jiaShuiYin/1.jpg';

    $newName='D:/myWorkspace/get_img/deal_img/jiaShuiYin/2.jpg';

    resizeImage($newWidth,$file_path,$newName);

    /*
    功能:按规定宽度等比压缩图片(压缩后图片的大小也会被压缩)
    */
    function resizeImage($maxwidth,$file_path,$name)
    {

    $im=imagecreatefromjpeg($file_path);
    $pic_width = imagesx($im);
    $pic_height = imagesy($im);

    if($maxwidth && $pic_width > $maxwidth)
    {
    $ratio = $maxwidth/$pic_width;

    $newwidth = $maxwidth;
    $newheight = $pic_height * $ratio;
    if(function_exists("imagecopyresampled"))
    {
    $newim = imagecreatetruecolor($newwidth,$newheight);
    $state=imagecopyresampled($newim,$im,0,0,0,0,$newwidth,$newheight,$pic_width,$pic_height);
    }else
    {
    $newim = imagecreate($newwidth,$newheight);
    $state=imagecopyresized($newim,$im,0,0,0,0,$newwidth,$newheight,$pic_width,$pic_height);
    }
    if($state)
    {
    if(!imagejpeg($newim,$name)){
    write_log($name,"图片写入出错");
    }
    imagedestroy($newim);
    }else
    {
    write_log($name,"图片写入出错");
    }
    }else
    {
    if (!copy($file_path,$name)) {
    write_log($name,"图片copy出错");
    }
    }
    }

  • 相关阅读:
    Unix系统中system函数的返回值
    vim 插件 for gbasic
    arch初认识
    TI IPNC Web网页之进阶修改
    Ti IPNC Web网页之ActiveX控件
    TI IPNC Web网页之网页修改教程
    OI,再见
    [OI]省选前模板整理
    OI刷题录——hahalidaxin
    51nod 小Z的trie(Trie+广义SAM)
  • 原文地址:https://www.cnblogs.com/linjinzhuang/p/6531869.html
Copyright © 2020-2023  润新知