How does PHP improve the quality of uploaded images without aliasing?

Source: Internet
Author: User
Tags imagejpeg
Title, in the face of fussy designers, said uploading pictures have jagged (PS: I don't quite see!). = =)

Can you tell me how to improve the picture quality when uploading pictures, no aliasing?


Reply to discussion (solution)

Upload is just a copy, not affect the picture quality
Of course, you can use GD, it's another matter.

Upload is just a copy, not affect the picture quality
Of course, you can use GD, it's another matter.

The wise, is to use the GD function, and do the scaling of these operations, you can help pointing it?

The code is as follows

function resizeimg ($from, $w =100, $h =100, $newfile) {$info = getimagesize ($from);  Switch ($info [2]) {Case 1: $im = Imagecreatefromgif ($from), break, Case 2: $im = Imagecreatefromjpeg ($from); Break  Case 3: $im = Imagecreatefrompng ($from); Break Default://exit (' Unsupported image format '); Break } $temp = PathInfo ($from); $name = $temp ["basename"];//filename $dir = $temp ["dirname"];//file is in the same folder $extension = $temp ["extension"];//file name extension $width = $info [0];//Gets the picture width $height = $info [1];//Gets the picture height $per 1 = round ($width/$height, 2);//Calculate the original aspect ratio $per 2 = round ($w/$h, 2);//calculate the thumbnail aspect ratio// Calculate scaling if ($per 1> $per 2| | $per 1== $per 2) {//The original aspect ratio is greater than or equal to the thumbnail aspect ratio, the width first $per = $w/$width;} if ($per 1< $per 2) {//The original aspect ratio is less than the thumbnail aspect ratio, then high priority $per = $h/$ Height } $temp _w = Intval ($width * $per),//Calculate the width of the original image after zooming $temp _h = intval ($height * $per);//Calculate the height of the original image after zooming $dst _im = Imagecreatetruecolor ($temp _w, $temp _h); Sizing imagecopyresized ($dst _im, $im, 0, 0, 0, 0, $temp _w, $temp _h, $width, $height); Output reduced image//exit ($newfile); Imagejpeg ($dst _im, $newfile, 100); ImagedeStroy ($dst _im); Imagedestroy ($im);}


There is also a section of code below

$file = $_files["Photo"]; $filename = $file ["Tmp_name"]; $size = $file [' Size '];    $type = $file [' type ']; $max _size=5*1024*1024;//echo $size; if ($type! = "Image/jpg" && $type! = "Image/jpeg" && $type! = "image/ PNG "&& $type! =" Image/gif ") {echo" "; exit;} if ($size > $max _size) {echo"; exit;} $udid =guid (); $target _file= " .. /photos/". $udid.".    JPG "; Copy ($filename, $target _file);/* $info =getimagesize ($target _file);   Print_r ($info); */resizeimg ($target _file, $NW, $nh, $target _file); $IFN = $target _file;  -----------Original image----$ofn = $target _file; ---the image name saved after the cut----$ext = Strtoupper (End (Explode ('. ', $IFN))); if (Is_file ($IFN) && ($ext = = "JPG" | | $ext = = "JPEG")) {$source = Imagecreatefromjpeg ($IFN);} ElseIf (Is_file ($IFN) && $ext = = "PNG") {$source = Imagecreatefrompng ($IFN);} ElseIf (Is_file ($IFN) && $ext = = "GIF") {$source = Imagecreatefromgif ($IFN);} $sourceWidth = Imagesx ($source); $sourceHeight = Imagesy ($source); $thumbWidth = $_post[' W ']; $thumbHeight = $_post[' h ']; $thumb = Imagecreatetruecolor ($thumbWidth, $thumbHeight); $x 1 = $_post[' x1 '); $y 1 = $_post[' y1 '); $x 2 = $_post[' X2 '); $y 2 = $_post[' y2 '); Imagecopyresampled ($thumb, $source, 0,0, $x 1, $y 1, $thumbWidth, $thumbHeight, $thumbWidth, $thumbHeight); Imagejpeg ($thumb, $ofn); Resizeimg ($target _file,100,100, $target _file);



Can you help to see where the problem is? Because of the GD function is not familiar with, I hope you can guide the guidance, thank you

Try to enable anti-aliasing (Imageantialias)

But you zoom in on the bitmap, the loss of precision is inevitable.

Try to enable anti-aliasing (Imageantialias)

But you zoom in on the bitmap, the loss of precision is inevitable.

Try, it seems no effect!!!

So that's "try."

All right, keep trying!

Found the problem, but thanks to the guidance of the owner



The original is the two functions have a relationship, hehe! You have to pay attention later.

  • 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.