The php image proportional scaling code is a user-uploaded image to specify the proportional size of the image. The principle is to calculate the proportional size of the image, the second step is to generate a small image with a fixed image size. However, it is a good way to set the image size to a value smaller than the set image size.
Php tutorial image proportional scaling code is a user-uploaded image to specify the proportion of the image, the principle is very simple is to calculate the size of the image into the proportion of the line, the second step is to generate a small image with a fixed image size. However, it is a good way to set the image size to a value smaller than the set image size.
<? Php
Header ("content-type: image/jpeg ");
$ Filename = hsdir. '/mljntc2p.jpg ';
$ Im = imagecreatefromjpeg ($ filename );
$ H = imagesy ($ im); // obtain the Target Image Height
$ New_img_width = 257;
$ New_img_height = 522;
$ Newim = imagecreate ($ new_img_width, $ new_img_height );
$ White = imagecolorallocate ($ newim, 255,255,255); // set the background color.
Imagecopyresized ($ newim, $ im, 0, 0, 0, 0, $ new_img_width, $ new_img_height, $ new_img_width, $ new_img_height );
Imagefilledrectangle ($ newim, 0, $ h, $ new_img_width, $ new_img_height, $ white );
// Fill in the target image height as the starting y coordinate to specify the intercepting width and height as the ending Coordinate
Imagejpeg ($ newim );
Imagedestroy ($ newim );
Imagedestroy ($ im );
?>
Code 2
<? Php
Header ("content-type: image/jpeg ");
$ Filename = 'myface.jpg ';
$ Im = imagecreatefromjpeg ($ filename );
$ New_img_width = 80;
$ New_img_height = 150;
$ Newim = imagecreate ($ new_img_width, $ new_img_height );
$ White = imagecolorallocate ($ newim, 255,255,255); // set the background color.
Imagecopyresized ($ newim, $ im, 0, 0, 0, 0, $ new_img_width, $ new_img_height, $ new_img_width, $ new_img_height );
Imagejpeg ($ newim );
Imagedestroy ($ newim );
Imagedestroy ($ im );
?>