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