Two php image proportional scaling-PHP Tutorial

Source: Internet
Author: User
Tags imagejpeg
The two php images are scaled proportionally. 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 thumbnail, php image, and other proportional scaling code. the code is an image with a specified proportional size based on the image uploaded by the user. The principle is simply to calculate the proportional ratio of the image size, 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.

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

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 );
?>

Http://www.bkjia.com/PHPjc/633018.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/633018.htmlTechArticlephp Image proportional scaling code is based on the user to upload images to specify the proportion of the size of the image, the principle is very simple is to calculate the size of the image into the proportion of the line, the second paragraph to generate a small image...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.