Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6815969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:52:12+00:00 2026-05-26T20:52:12+00:00

I am trying to downsize some transparents images in PHP with GD, and whenever

  • 0

I am trying to downsize some transparents images in PHP with GD, and whenever I do, there is a weird black-ish border that is added around it.

Before
before

After
enter image description here

Code

<?php
    $image = imagecreatefromstring(file_get_contents('logo.png'));
    $width = imagesx($image);
    $height = imagesy($image);

    $newWidth = $width - 1;
    $newHeight = $height - 1;
    $output = imagecreatetruecolor($newWidth, $newHeight);
    imagecolortransparent($output, imagecolorallocatealpha($output, 0, 0, 0, 127));
    imagealphablending($output, false);
    imagesavealpha($output, true);
    imagecopyresampled($output, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);

    header('Content-Type: image/png');
    imagepng($output);
?>

It seems that if I change the code for the new dimensions to be the same as the old (removing the - 1), no black borders appear. So the resize is causing the problem.

Does anyone have an idea what might be wrong?

Edit: I just realized it only happens with imagecopyresampled and not imagecopyresized. However, imagecopyresampled gives a far better visual effect and I’d like to make it work if possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:52:13+00:00Added an answer on May 26, 2026 at 8:52 pm

    I think the problem here is your source image.

    What you have is not a true-color PNG with alpha channel, but an indexed-color PNG with a transparent color. This is apparent if you open the image in Photoshop:

    Image as seen in Photoshop

    This image was created with anti-aliasing already (which gives the yellow text that white-ish border seen here), but when you re-size it, the sub-pixel calculations may go outside of their borders a bit.

    I suspect if you fix the image, making it full RGB with an alpha channel, you won’t have this problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have some business logic that traps some logically invalid situations, e.g. trying to
I'm trying to downsize an image quality before it is sent to the PHP
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
I have some long-running operations that number in the hundreds. At the moment they
We are trying to cut back some space on our linux-based server and noticed
I'm trying to wrap my head around CouchDB . I'm trying to switch off
I'm writing some pretty CPU-intensive, concurrent numerical code that will process large amounts of
I've had some success comparing strings using the PHP levenshtein function. However, for two
Trying to setup a SQL stored procedure that if the variable passed to it
I've got a very large and mature C++ code base that I'm trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.