PHP implements simple image scaling.
- /**
- * The Images class is an 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 image size
- list($s_w,$s_h)=getimagesize($source);
- //Generate 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
|