PHP simple method of creating a compression graph, php compression Graph
This article describes how to create a simple compression graph in PHP. We will share this with you for your reference. The details are as follows:
<? Php // create a compression graph function _ create_thumbnail ($ srcFile, $ toW, $ toH, $ toFile = "") {if ($ toFile = "") {$ toFile = $ srcFile;} $ info = ""; $ data = getimagesize ($ srcFile, $ info); if (! $ Data) return false; // load the file to the resource variable im switch ($ data [2]) {case 1: $ im = imagecreatefromgif ($ srcFile); break; case 2: $ im = imagecreatefromjpeg ($ srcFile); break; case 3: $ im = imagecreatefrompng ($ srcFile); break ;} // calculate the width and height of the thumbnail $ srcW = imagesx ($ im); $ srcH = imagesy ($ im); $ toWH = $ toW/$ toH; $ srcWH = $ srcW/$ srcH; if ($ toWH <= $ srcWH) {$ ftoW = $ toW; $ ftoH = (int) ($ ftoW * ($ srcH/$ srcW);} else {$ f ToH = $ toH; $ ftoW = (int) ($ ftoH * ($ srcW/$ srcH);} if (function_exists ("imagecreatetruecolor ")) {$ ni = imagecreatetruecolor ($ ftoW, $ ftoH); // create a true color image if ($ ni) {// copy part of the image and adjust the size to maintain a good definition. imagecopyresampled ($ ni, $ im, 0, 0, 0, 0, $ ftoW, $ ftoH, $ srcW, $ srcH);} else {// copy part of the image and resize it $ ni = imagecreate ($ ftoW, $ ftoH); imagecopyresized ($ ni, $ im, 0, 0, 0, 0, $ ftoW, $ ftoH, $ srcW, $ srcH) ;}} else {$ n I = imagecreate ($ ftoW, $ ftoH); imagecopyresized ($ ni, $ im, 0, 0, 0, 0, $ ftoW, $ ftoH, $ srcW, $ srcH);} // save it to the file in the. PNG format imagepng ($ ni, $ toFile); // output the image to the browser or file ImageDestroy ($ ni) in PNG format ); imageDestroy ($ im) ;}?>