0

The first option works, the second doesn’t … I don’t get why? I take an image 1500 by 1500 pixels, if it gets passed through the first option the result is right, if it gets passed through the second, I get a black border on the right and on the bottom …

if ($this_imagesize[0] > 1000)
    {
        $thumb_source = imagecreatefromjpeg('/path/' . $this_image_id . '.jpg');

        $thumbnail = imagecreatetruecolor(1000, intval(1000 * ($this_imagesize[1] / $this_imagesize[0])));

        imagefill($thumbnail, 0, 0, imagecolorallocate($tn, 255, 255, 255));

        imagecopyresampled($thumbnail, $thumb_source, 0, 0, 0, 0, 1000, intval(1000 * ($this_imagesize[1] / $this_imagesize[0])), $this_imagesize[0], $this_imagesize[1]);

        unlink('/path/' . $this_image_id . '.jpg');

        imagejpeg($thumbnail, '/path/' . $this_image_id . '.jpg', 75);
    }

if ($this_imagesize[1] > 1000)
    {
        $thumb_source = imagecreatefromjpeg('/path/' . $this_image_id . '.jpg');

        $thumbnail = imagecreatetruecolor(intval(1000 * ($this_imagesize[0] / $this_imagesize[1])), 1000);

        imagecopyresampled($thumbnail, $thumb_source, 0, 0, 0, 0, intval(1000 * ($this_imagesize[0] / $this_imagesize[1])), 1000, $this_imagesize[0], $this_imagesize[1]);

        unlink('/path/' . $this_image_id . '.jpg');

        imagejpeg($thumbnail, '/path/' . $this_image_id . '.jpg', 75);
    }
  • What were the error messages you got when it didn't work? What language is this in? – Daniel Compton Jun 07 '15 at 19:37
  • 1
    There’s no error message—the second if statement just generates an image with black borders … it’s PHP … – Christian Schröter Jun 07 '15 at 19:42
  • This happens because you are creating a back layer a larger size than what's on top so the background (which in a program like photoshop would be transparent) is black. You are likely not calculating dimensions properly. – Rasclatt Jun 07 '15 at 21:16

0 Answers0