Image compression in PHP

Source: Internet
Author: User
Now I want to compress the picture, for example, 640x480 image is now stored 600k I want to achieve compression into 640x 480 480k size of the picture This can be achieved? If this compresses the picture will not be damaged? How exactly do you want to do it? Urgent request?????


Reply to discussion (solution)

Reduce the pixels of the picture can be, there may be a problem is the image display effect and the original effect of color difference, there are defects.

You can use the GD library to generate thumbnails

 
  


Picture compression is the same

? Test: http://blog.csdn.net/fdipzone/article/details/9316385

No!
640x 480 600k compression into 640x 480 480k, then remove the 120k will inevitably take away 1/5 of the picture data, resulting in picture quality decline
Unless your original image is Bitmap mode (Bmp,tiff), but
GIF is lossless compression, but only 256 colors (that is, color information is lost)
JPEG is lossy compression, apparently lossy two words already good to explain the problem
PNG is lossless compression, but if it is 256 color, it is obviously lost color information, and true color is equal to no compression

Try to reduce quality.

There are three ways I can use PHP:

1.

$im = Imagecreatefromjpeg (' 3.jpg ');   Imageinterlace ($im, true);   Imagejpeg ($im, './3.jpg ');   Var_dump (Imageinterlace ($im, true));

This can compress the picture by 2k (this is the result of my picture)

2.
       $image = @imagecreatefromjpeg ("9.jpg");        Imagejpeg ($image, ' 90.jpg ', 20); /* Compression level 0-100*/       Imagedestroy ($image);

This can compress the picture to 90%. Imagejpeg ($image, ' 90.jpg ', 0); 143k = 7k
Of course, this picture will not have the original definition. So with 20 can compress the picture can achieve I want the state, not only can compress to 17k, with the naked eye and the original image is not much difference.
This is Figure 9.

3.php ImageMagick extension, this no specific test can compress to how much

No!
640x 480 600k compression into 640x 480 480k, then remove the 120k will inevitably take away 1/5 of the picture data, resulting in picture quality decline
Unless your original image is Bitmap mode (Bmp,tiff), but
GIF is lossless compression, but only 256 colors (that is, color information is lost)
JPEG is lossy compression, apparently lossy two words already good to explain the problem
PNG is lossless compression, but if it is 256 color, it is obviously lost color information, and true color is equal to no compression


I basically realized it in two ways. The trouble is stained with a knot.

? Test: http://blog.csdn.net/fdipzone/article/details/9316385


Thanks, this is just the way I didn't experiment.

Knot stickers are your own business.


No!
640x 480 600k compression into 640x 480 480k, then remove the 120k will inevitably take away 1/5 of the picture data, resulting in picture quality decline
Unless your original image is Bitmap mode (Bmp,tiff), but
GIF is lossless compression, but only 256 colors (that is, color information is lost)
JPEG is lossy compression, apparently lossy two words already good to explain the problem
PNG is lossless compression, but if it is 256 color, it is obviously lost color information, and true color is equal to no compression


I basically realized it in two ways. The trouble is stained with a knot.
  • 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.