SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Noise with ImageCopyResampled

    It is almost the holiday season and to my surprise it is unfortunately already snowing in my transparent images.
    The situation is that I am uploading transparent PNG images with the given code below and the result is that there is noise in the final image.

    Searching the web for answers tells me that more people had this but any solution is not to be found
    only PHP.net shows me that in the past there where even some bug reports about it.
    https://bugs.php.net/bug.php?id=45030
    https://bugs.php.net/bug.php?id=41820

    Switching from imagecopyresampled to imagecopyresized solves it but then the quality of the image is to cry for.

    Can anyone tell me more about the problem, if you also encountered it and what you did to fix it?

    PHP Code:
    $original_fileimagecreatefrompng($_FILES['image']['tmp_name']);
    $new_imageimagecreatetruecolor($new_width$new_height);

    $transparentimagecolorallocatealpha($new_image255255255127);
    imagefilledrectangle($new_image00$new_width$new_height$transparent);
    imagealphablending($new_imagefalse);
    imagesavealpha($new_image,true);
                        
    imagecopyresampled($new_image$original_file0000$new_width$new_height$orig_width$orig_height);        
    imagePNG($new_image$destination); 
    Image result example (boosted result image so it's easy to see what I mean)
    example.jpg

  2. #2
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,358
    Mentioned
    80 Post(s)
    Tagged
    3 Thread(s)
    Can you try Imagemagick ?

    I am not that good at GD but in an example I made a while ago I used imagecolortransparent ( $canvas, $white ); The example is half way down this page: Watermark with GD


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •