Use of the PHP GD library

Source: Internet
Author: User

<?php/** *  Resize Picture  *  $path The width of the picture is greater than $width, and so on than the zoom  *  $path picture height is greater than $height cut into multiple pictures   *  @param   $path   picture address  *  @param   $width  integer|string   picture width  *   @param   @height  integer|string  Image height  */function imgresize ($path,  $width,   $height)  {  //  store the resulting picture path    $imgPaths  = array ();   //   Get picture width/height/type   list ($srcW,  $srcH,  $type)  = getimagesize ($path);   $type  -= 1;  //  Create a source image    $imagecreatefromFuns  = array (' Imagecreatefromgif ',  ' imagecreatefromjpeg ',  ' imagecreatefrompng ');   $src  = $ imagecreatefromfuns[$type] ($path);  //  the width of the picture is greater than $width zoom   if (  $srcW  >   $width  )  {     $dstHeight  =  $srcH  *  ($width  /   $srcW);     //  Create a new True color image      $dst  = imagecreatetruecolor (  $width,  $dstHeight  ) ;     imagecopyresampled ($dst,  $src,  0, 0, 0, 0,  $width ,  $dstHeight,  $srcW,  $srcH);     $src  =  $dst;      //  Update the width and height of the original artwork      $srcW  =  $width;     $srcH  =  $dstHeight;  }  else {    //  No adjustment width       $width  =  $srcW;  }    //  picture height is greater than $height cut into multiple pictures    if (  $srcH  >  $height  )  {    //  height position of cut       $srcY  = 0;    do {      $ dstheight =  ($srcY  +  $height  >  $srcH)  ?  ($srcH  -  $srcY)  :  ($height);       $dst  = imagecreatetruecolor (  $width,  $dstHeight  );       imagecopyresampled ($dst,  $src,   0, 0, 0, $ srcy,  $width,  $dstHeight,  $width,  $dstHeight);       $ filepath =  './img/'  . md5 (Microtime (true))  .  '. jpg ';        $imgPaths [] =  $filePath;       imagejpeg ($DST,  $ FilePath)       is_resource ($DST)  and imagedestroy ($DST);        $srcY  +=  $dstHeight;     }while ($srcY  < $ SrcH);  }  else {    //  If the height of   is adjusted to the original image (and possibly after the width is adjusted) Save as file      $filePath  =  './img/'  . md5 (Microtime (true))  .  '. jpg ';     $imgPaths [] =  $filePath;     imagejpeg ($src,  $filePath);  }  //  Free memory   isset ($SRC)  and is_resource ($SRC)  and imagedestroy ($SRC);   isset ($DST)  and is_resource ($DST)  and imagedestroy ($DST);  return  $imgPaths;} /** *  Adjust image clarity  *  @param  string  $path    picture path  *  @param   string  $quality   Clarity  *  @return  string  new picture Path  */function requality (   $path,  $quality  )  {     $image _type = image_type_to_ Extension (Exif_imagetype ($path),  false);     $fun  =  "imagecreatefrom{$image _ Type} ";     $src  =  $fun ($path);     $newPath  =  Generateuniquefilepath ('./img/');     imagejpeg ($src,  $newPath,  $quality);     return  $newPatH;} /** *  generate a unique file path  *  @param   $basePath  string  folder path  *  @param  $ suffix string *  @return  string  file path  */function generateuniquefilepath ($ basepath,  $suffix = '. jpg ')  {   $filePath  =  $basePath  . md5 (Microtime ( true)  .  $suffix;  return  $filePath;} Header (' content-type:image/png '); $path  =  '/img/jjj.jpg '; $imgPaths  = imgresize ($path,  10000, 10000);// requality ($path,  1);


Use of the PHP GD library

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.