1. libgd
  2. Untitled project
  3. gd-libgd
  4. Issues

Issues

Issue #99 new

Resize Artifact

Yann DANINOS
created an issue

Hi Pierre,

Following your recommandation on the mailing list I open a new issue : If I resize a picture to a size which is not a multiple of the original size I have artifacts on the white background.

I just had a test on php5.53 and the bug is still here :

Here is the code I used to test (test.jpg is a 1000x1000 jpeg)

<?php
$filename = 'test.jpg';
$percent = $_GET["scale"] ?  $_GET["scale"] : 1;

// 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);

You can find the resulting jpg in attachment (If you can't see the artifact just add contrast in photoshop)

Comments (1)

  1. Никита Сковорода

    A better testcase:

    <?php
    
    // Request input parameters
    $percent = isset($_GET["scale"]) ?  floatval($_GET["scale"]) : 1;
    
    // Build original image
    $width = $height = 1000;
    $image = imagecreatetruecolor($width, $height);
    $white = imagecolorallocate($image, 255, 255, 255);
    imagefill($image, 0, 0, $white);
    
    // Get new dimensions
    $new_width = $width * $percent;
    $new_height = $height * $percent;
    
    // Resample
    $image_p = imagecreatetruecolor($new_width, $new_height);
    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
    
    // Output
    header('Content-Type: image/png');
    imagepng($image_p, null);
    
  2. Log in to comment