PHP image compression

Source: Internet
Author: User

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

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.