This article illustrates a simple way to create a compression diagram in PHP. Share to everyone for your reference, specific as follows:
<?php//Create compression graph function _create_thumbnail ($srcFile, $toW, $toH, $toFile = "") {if ($toFile = = "") {$toFile = $s
Rcfile;
} $info = "";
$data = getimagesize ($srcFile, $info);
if (! $data) return false;
Load the file into 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
///compute 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 {$ftoH = $toH;
$ftoW = (int) ($ftoH * ($srcW/$srcH)); } if (Function_exists ("Imagecreatetruecolor")) {$ni = Imagecreatetruecolor ($ftoW, $ftoH);//Create a new True color image if ($ni
{//resampling copies of partial images and resizing to maintain better sharpness imagecopyresampled ($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH); } ELSE {//Copy part of image and resize $ni = Imagecreate ($ftoW, $ftoH);
Imagecopyresized ($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
} else {$ni = Imagecreate ($ftoW, $ftoH);
Imagecopyresized ($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH); //Save to file Unified for. png format imagepng ($ni, $toFile);
Output the image to the browser or file Imagedestroy ($ni) in PNG format;
Imagedestroy ($im);
}?>
For more information on PHP related content readers can view the site topics: "PHP graphics and picture Operation skills Summary", "PHP array of Operations Skills encyclopedia", "PHP Mathematical Calculation Skills Summary", "PHP date and Time usage summary", "PHP object-oriented Programming Program", Summary of PHP string usage, Getting Started tutorial on Php+mysql database operations, and summary of common PHP database operations techniques
I hope this article will help you with the PHP program design.