PHP: how to generate a thumbnail based on the original ratio. how to generate a thumbnail based on the php ratio?

Source: Internet
Author: User
PHP implements the method of generating thumbnails based on the original proportion. PHP: how to generate a thumbnail based on the original proportion. the example in this article describes how to generate a thumbnail based on the original proportion in php. Share it with you for your reference. The details are as follows: how to use PHP to generate a thumbnail based on the original proportion, and how to generate a thumbnail based on the php proportion.

This example describes how to use PHP to generate a thumbnail based on the original proportion. We will share this with you for your reference. The details are as follows:

<? Php $ image = "jiequ.jpg"; // source image $ imgstream = file_get_contents ($ image); $ im = imagecreatefromstring ($ imgstream); $ x = imagesx ($ im ); // get the image width $ y = imagesy ($ im); // get the image height // The scaled size $ xx = 140; $ yy = 200; if ($ x> $ y) {// The image is larger than $ sx = abs ($ y-$ x)/2); $ sy = 0; $ thumbw = $ y; $ thumbh = $ y;} else {// The Image height is equal to or equal to the width $ sy = abs ($ x-$ y)/2.5 ); $ sx = 0; $ thumbw = $ x; $ thumbh = $ x;} if (function_exists ("imagecreatetruecolor") {$ dim = Imagecreatetruecolor ($ yy, $ xx); // create the target graph gd2} else {$ dim = imagecreate ($ yy, $ xx ); // create a target Image gd1} imageCopyreSampled ($ dim, $ im, $ sx, $ sy, $ yy, $ xx, $ thumbw, $ thumbh ); header ("Content-type: image/jpeg"); imagejpeg ($ dim, false, 100);?>

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.