Imagecopyresampled () The quality is higher than imagecopyresized () after changing the image size.

Source: Internet
Author: User
Tags imagejpeg

The function of changing the size of a picture in a PHP program most people want to use imagecopyresized (), but after testing, it is found that using imagecopyresampled () changes the image quality higher.

Let's take a look at the comparison results.

Original:

Use imagecopyresized () to reduce the picture by half

Code:

<?php
File and new size
$filename = ' test.jpg ';
$percent = 0.5;
Content type
Header (' Content-type:image/jpeg ');
Get New Sizes
List ($width, $height) = getimagesize ($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;
Load
$thumb = Imagecreatetruecolor ($newwidth, $newheight);
$source = Imagecreatefromjpeg ($filename);
Resize
Imagecopyresized ($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
Output
Imagejpeg ($THUMB);
?>

Change the picture after:

Use imagecopyresampled () to reduce the picture by half

Code:

<?php
The file
$filename = ' test.jpg ';
$percent = 0.5;
Content type
Header (' Content-type:image/jpeg ');
Get New Dimensions
List ($width, $height) = getimagesize ($filename);
$new _width = $width * $percent;
$new _height = $height * $percent;
Resample
$image _p = Imagecreatetruecolor ($new _width, $new _height);
$image = Imagecreatefromjpeg ($filename);
Imagecopyresampled ($image _p, $image, 0, 0, 0, 0, $new _width, $new _height, $width, $height);
Output
Imagejpeg ($image _p, NULL, 100);
?>

Change the picture after:

It can be seen that imagecopyresampled () changes the image size after the quality is higher than imagecopyresized ().

Imagecopyresampled () The quality is higher than imagecopyresized () after changing the image size.

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.