zoukankan      html  css  js  c++  java
  • PHP之缩略图

     1 <?php
     2     //原图上 采样, 拷贝 到缩略图, 修改拷贝之后的大小
     3 
     4     //使用函数 imagecopyresampled()
     5 
     6     //引入文件
     7     $img_src = './psb.jpg';
     8 
     9     // $percent = 0.5;
    10     //设置等比例
    11     $width = 227;
    12     $height= 400;    
    13 
    14     rationThumb($img_src,$width,$height);
    15 public function rationThumb($img_src,$width,$height){
    16     
    17 
    18     //内容类型
    19     header("Content-type:image/jpeg");
    20 
    21     //获取原图 img_src的宽高
    22     list($src_w,$src_h) = getimagesize($img_src);  //return $w,$h,$type,$attr
    23     //获取 等比例限制的 宽和高
    24     //$new_w = $src_w * $percent;
    25     //$new_h = $src_h * $percent;
    26 
    27     $ratio = $src_w / $src_h;
    28     if ($width/$height > $ratio) {
    29         $width = $height*$ratio;
    30     }else{
    31         $height = $width/$ratio;
    32     }
    33 
    34     //重新取样
    35     $img_p = imagecreatetruecolor($width, $height);
    36     $image = imagecreatefromjpeg($img_src);
    37 
    38     imagecopyresampled($img_p, $image, 0, 0, 0, 0, $width, $height, $src_w, $src_h);
    39 
    40     imagejpeg($img_p);
    41     imagedestroy($img_p);
    42     imagedestroy($image);
    43 
    44 }
  • 相关阅读:
    day4
    day3
    day2
    day1
    spring-boot-note
    spring-boot-cli
    jquery ajax rest invoke
    spring-boot
    docker mysql
    jpa OneToMany
  • 原文地址:https://www.cnblogs.com/sharecorner/p/6183556.html
Copyright © 2011-2022 走看看