GD Library, is the PHP processing graphics extension Library, the GD library provides a series of APIs for processing pictures, using the GD library can process pictures, or create pictures. The GD library on the website is usually used to generate thumbnails, or to add watermarks to images, or to generate Chinese character verification codes, or to generate reports on site data. In PHP processing images, you can use the GD library, and the GD library started with GIF support, but because GIF uses a copyright dispute LZW algorithm, will cause legal problems, so from the GD Library 1.6 version of all the GIF support removed, but also in the GD library 2.0.28 version and added back. If you use a version of GD library between the two, the GIF correlation function is not available.
This article for you to introduce how PHP uses the GD library to generate thumbnails, there is a good example below, we can refer to the following
PHP uses the GD library to generate thumbnails.
<form method= "POST" action= "suo_do.php" enctype= "Multipart/form-data" > <input type= "file" name= "Pic"/> <input type= "Submit" value= "Upload 1"/> </form> <?php Header ("CONTENT-TYPE:TEXT/HTML;CHARSET=GBK"); Ini_set ("Date.timezone", "Asia/chong"); Determine if the file is empty if (empty ($_files)) {echo "Upload file too large"; exit;}//Determine if the file upload has an error if ($_files[' pic ' [' ERROR ']) {echo "Upload file"; exit;}//Judgment File type is illegal to get file suffix $allowtype =array ("JPG", "PNG", "JPEG", "gif"); $a =explode ('. ', $_files[' pic ' [' name ']); $index =count ($a)-1; $ex =strtolower ($a [$index]); if (!in_array ($ex, $allowtype)) {echo "uploads the file illegally"; exit;} $file =date (' Ymdhis '). Rand (). ".". $ex; $SRC =$_files[' pic ' [' tmp_name ']; $des = "upload/". $file; $rs =move_uploaded_file ($SRC, $des); Thumbnails//Read uploaded images $image =imagecreatefromjpeg ($des); $a =getimagesize ($des); $w = $a [0]; $h = $a [1]; if ($w > $h) {$width =300; $height = $width/$w * $H;} else if ($w < $h) {$height =300; $width = $height/$h * $W;} else{$width =300; $height = 300;}//create blank new picture $newimage =imagecreatetruecolor ($width, $heigHT); Copy source picture content copy new picture imagecopyresized ($newimage, $image, 0,0, 0,0, $width, $height, $w, $h); $filename = "Upload/s_". $file; Imagejpeg ($newimage, $filename);