PHP implements the method of creating thumbnails from the upload file,
The examples in this article describe how PHP implements the creation of thumbnails from uploaded files. Share to everyone for your reference. The implementation method is as follows:
<?PHPIF ($_request[' action ']== "add") {$userfile = $HTTP _post_files[' photo '] [' tmp_name ']; $userfile _name = $HTTP _ post_files[' photo ' [' name ']; $userfile _size = $HTTP _post_files[' photo ' [' size ']; $userfile _type = $HTTP _post_files[' Photo ' [' type '];///////////////////////////get-declare DIMENSIONS//$dimension = getimagesize ($userfile); $large _ width = $dimension [0]; GET PHOTO width$large_height = $dimension [1]; GET PHOTO height$small_width = 120; DECLARE THUMB width$small_height = 90; DECLARE THUMB height///////////////////////////check SIZE//if ($userfile _size>102400) {$error = 1; $msg = "The photo is over 100kb. Please try again. ";} CHECK TYPE (IE and OTHERS)//if ($userfile _type= "Image/pjpeg") {if ($userfile _type!= "Image/jpeg") {$error = 1; $msg = "The photo must be JPG"; }}////////////////////////////////check width/height//if ($large _width!=600 or$large_height!=400) {$error =1; $msg = " The photo must be 600x400 pixels ";} ////////////CREATE thumb/upload THUMB and PHOTO///if ($error <>1) {$image = $userfile _name; If you want-to-insert it to the database $pic = Imagecreatefromjpeg ($userfile); $small = Imagecreatetruecolor ($small _width, $small _height); Imagecopyresampled ($small, $pic, 0,0,0,0, $small _width, $small _height, $large _width, $large _height); if (imagejpeg ($small, "Path/to/folder/to/upload/thumb". $userfile _name) {$large = Imagecreatetruecolor ($large _ width, $large _height); Imagecopyresampled ($large, $pic, 0,0,0,0, $large _width, $large _height, $large _width, $large _height); if (imagejpeg ($large, "Path/to/folder/to/upload/photo". $userfile _name)) {} else {$msg = "A problem has occured. P Lease try again. "; $error = 1;} } else {$msg = "A problem has occured. Please try again. "; $error = 1; }}/////////////////////////////////////////////////If Everything went right a photo (600x400) and///a thumb (120x90) wer e uploaded to the given folders}?><title>Create Thumb</title>
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/978381.html www.bkjia.com true http://www.bkjia.com/PHPjc/978381.html techarticle PHP Implementation of the method of creating thumbnails from the upload file, this article describes the PHP implementation of the method of creating thumbnails from the upload file. Share to everyone for your reference. The concrete implementation method is as follows: ...