An instance of image scaling in PHP

  • 2020-05-30 19:43:35
  • OfStack

     // Proportional scaling of images  

     // because PHP Only resources can be manipulated, so copy the image that needs to be scaled and create it as a new resource  

     // Gets the width and height of the source image  

     // Specifies the maximum width (possibly height) that will be zoomed out  

     // According to the maximum value 300 And work out the other 1 The length of the edges, the width and height of the scaled image  
     if($w > $h){ 

     // The statement 1 a $w Wide, $h High true-color picture resources  
     $image=imagecreatetruecolor($w, $h); 

     // Key functions, parameters (target resource, source, start coordinates of target resource x,y,  The start coordinates of the source resource x,y, The width and height of the target resource w,h, The width and height of the source resource w,h )  
     imagecopyresampled($image, $src, 0, 0, 0, 0, $w, $h, $size_src['0'], $size_src['1']); 

     // Tells the browser to parse it as a picture  

     // Destruction of resources  


Related articles: