Picture compression is the picture clipping, in which the production process and image watermark is very similar, the difference is that the image compression needs to copy the existing image to the memory at a certain proportion.
The following code is given:
<?php/* Open the picture */$src = "bg.jpg"; $info = getimagesize ($SRC); $type = Image_type_to_extension ($info [2],false); $fun = " Imagecreatefrom ". $type; $image = $fun ($SRC);/* operation Picture *///1. Create a 300,200 true color image $image_thumb = Imagecreatetruecolor ( 300,200)//2. Core steps, copy the original image to the true Color picture imagecopyresampled ($image _thumb, $image, 0, 0, 0, 0,, $info [0], $info [1]);//3. Destroy the original picture Imagedestroy ($image);/* Output Picture *///browser header ("Content-type:". $info [' MIME ']); $fun = "image". $type; $fun ($image _ thumb);//Save Picture $fun ($image _thumb, ' BG_TB. $TYPE);/* Destroy Picture */imagedestroy ($image _thumb);
For more information on PHP picture operations, refer to the following articles:
Image Watermark Making
Text watermark
Image Verification Code
Chinese character Verification Code
Character Verification Code
Chinese filter
About GD Library
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
PHP image compression