- // Specify the file path and scaling ratio
- $filename = 'test.jpg';
- $percent = 0.5;
- // Specify the header file Content type value
- header('Content-type: image/jpeg');
- // Get the width and height of the image
- list($width, $height) = getimagesize($filename);
- $newwidth = $width * $percent;
- $newheight = $height * $percent;
- // Create an image. The received parameters are width and height respectively, and the generated resource handle is returned.
- $thumb = imagecreatetruecolor($newwidth, $newheight);
- //Get the source file resource handle. The received parameter is the image path and the handle is returned
- $source = imagecreatefromjpeg($filename);
- // Cut all fields of the source file and reduce it to the target image. The first two are resource handles
- imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
- // Output to the browser
- imagejpeg($thumb);
- ?>
Copy code
|