How to Use php and Other proportional scaling images,
This article describes how to implement image compression in PHP. You can directly upload the code, imgzip ($ src, $ newwid, $ newhei), based on the specific application reference or improvement) this function carries the original image, the width required for scaling, and the scaling length.
<? 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 [1]); // 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);?>
I hope this article will help you with PHP programming.