-
-
/** - * Images class Image processing class
- * @author pan
- * @package application.controllers
- * @since 1.0
- */
- class Images
- {
- /**
- * Zoom image
- * @param $source original image
- * @param $newfile new image
- * @param $pre zoom ratio
- */
- public function thumn($source,$pre,$newfile )
- {
- //Get the image size
- list($s_w,$s_h)=getimagesize($source);
- //Generate a new image size
- $new_w=$s_w*$pre;
- $new_h=$s_h* $pre;
//Create a new image
- $new_f=imagecreatetruecolor($new_w, $new_h);
- //Create an image with a resource image
- $sour_f=imagecreatefromjpeg($source);
- //Copy the resource image to a new image
- imagecopyresampled($new_f, $sour_f, 0, 0, 0, 0, $new_w, $new_h, $s_w, $s_h);
- //Output the image to the browser
- imagejpeg( $new_f,$newfile);
imagedestroy($new_f);
- imagedestroy($sour_f);
- }
- }
- ?>
-
Copy code
The above is a simple code to implement image scaling in PHP for the reference of beginners.
|