PHP and Other proportional scaling image details and instance code,
Run the Code directly. The imgzip ($ src, $ newwid, $ newhei) function includes the original image, the width required for scaling, and the length of scaling. The Code has been commented out. If you don't understand it, leave a message. Haha
<? Php // compress image thumbnails $ src = "xiezheng.jpg"; $ newwid = 640; $ newhei = 480; function imgzip ($ src, $ newwid, $ newhei) {$ imgInfo = getimagesize ($ src); $ imgType = image_type_to_extension ($ imgInfo [2], false); $ fun = "imagecreatefrom {$ imgType }"; // declare the image to open the image in the memory $ image = $ fun ($ src); // you can easily configure the length, width, and height. The setting box is the variable wid, the height is hei $ wid = $ imgInfo [0]; $ hei = $ imgInfo [1]; // you can determine the length and width to facilitate proportional scaling, 500,320 if ($ wid> $ hei) {$ wid = $ newwid; $ hei = $ newwid/($ wi D/$ hei);} else {$ wid = $ newhei * ($ wid/$ hei); $ hei = $ newhei ;} // create an image in the memory $ images2 = imagecreatetruecolor ($ newwid, $ newhei ); // create a 500*320 image // copy the original image to the new image // imagecopyresampled ($ dst_image, $ src_image, $ dst_x, $ dst_y, $ src_x, $ src_y, $ dst_w, $ dst_h, $ src_w, $ src_h) imagecopyresampled ($ images2, $ image, 0, 0, 0, 0, $ wid, $ hei, $ imgInfo [0], $ imgInfo [0]); // destroy the original image imagedestroy ($ image); // directly output the image File header ("Content-type :". $ imgInfo ['mime ']); imagejpeg ($ images2); // Save the image to the new file imagejpeg ($ images2, 'new.jpg', 100 ); // 10 code output image quality 0-100 100 highest quality // destroy imagedestroy ($ images2);} imgzip ($ src, $ newwid, $ newhei);?>
Effect
Before Compression
After compression
The above is the sorting of PHP and Other proportional scaling images. We will continue to add relevant materials in the future. Thank you for your support for this site!