美文网首页
url读取过程---图片缩放

url读取过程---图片缩放

作者: 刚_dbac | 来源:发表于2018-01-10 17:15 被阅读0次

    url

    https://three.api.skinrun.me/web/index/imgs?w=500&h=500&url={$goodsInfo['thumbs']}

    调用截取函数

    public function imgs(){

      $url = $_GET['url'];

      $width = $_GET['w'];

      $height = $_GET['h'];

      imageResizer($url,$width,$height);

    }

    function imageResizer($url, $width, $height)

    {

      $imgType = pathinfo($url, PATHINFO_EXTENSION);

      if ($imgType == 'png')

    {

          header('Content-Type: image/png');

      } else

      {

          header('Content-Type: image/jpeg');

      }

      list($width_orig, $height_orig) = getimagesize($url);

      $ratio_orig = $width_orig / $height_orig;

      if ($width / $height > $ratio_orig)

    {

          $width = $height * $ratio_orig;

      } else

      {

          $height = $width / $ratio_orig;

      }

      $image_p = imagecreatetruecolor($width, $height);

      $image = imagecreatefromjpeg($url);

      if (!$image)

    {

          $image = imagecreatefrompng($url);

      }

      imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

      if ($imgType == 'png')

    {

          imagepng($image_p);

      } else

      {

          imagejpeg($image_p);

      }

    }

    注意:开启GD库

    相关文章

      网友评论

          本文标题:url读取过程---图片缩放

          本文链接:https://www.haomeiwen.com/subject/stmonxtx.html