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

  • Home
  • SEARCH
  • 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 6116119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:10:11+00:00 2026-05-23T15:10:11+00:00

i’m working on creating one PNG image from two others. Image A and B

  • 0

i’m working on creating one PNG image from two others.

Image A and B have the same dimensions, they are both 200x400px. The final image the same.

I’m using the GD library with PHP.

So my idea was to create a PNG-24 from my original PNG-8, then use color transparency and finally copy the second image into
this new PNG-24. The problem appears in the first step anyway, when going from PNG-24 to PNG-8 with color transparency:

This is to get the original PNG-8 and it’s dimensions:

$png8 = imagecreatefrompng($imageUrl);
$size = getimagesize($imageUrl);

Now i create a new PNG and fill it’s background with a green color (not present in the images):

$png24 = imagecreatetruecolor($size[0], $size[1]);
$transparentIndex = imagecolorallocate($png24, 0x66, 0xff, 0x66);
imagefill($png24, 0, 0, $transparentIndex);

This is for making the green color transparent:

imagecolortransparent($png24, $transparentIndex);     

Then i copy the png8 into the PNG-24:

imagecopy($png24, $png8, 0, 0, 0, 0, $size[0], $size[1]);

So here’s the problem: the original PNG-8 looks good, but it has a green border surrounding the shape within the original image. It’s difficult to explain really. Seems like some part of the green background is left in the remaining PNG.

What can i do?

thanks in advance

best regards,

Fernando

  • 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-23T15:10:12+00:00Added an answer on May 23, 2026 at 3:10 pm

    I had some problems with png transparency before and was able to solve them with this pattern:

    // allocate original image to copy stuff to
    $img = imagecreatetruecolor(200, 100);
    
    // create second image
    $bg = imagecreatefrompng('bg.png');
    
    // copy image onto it using imagecopyresampled
    imagecopyresampled($img, $bg, 0, 0, 0, 0, 200, 100, 200, 100);
    imagedestroy($bg);
    
    // create third image
    // do same routine
    $fg = imagecreatefrompng('fg.png');
    imagecopyresampled($img, $fg, 50, 50, 0, 0, 50, 50, 50, 50);
    imagedestroy($fg);
    
    // output image
    imagepng($img);
    imagedestroy($img);
    

    I think the only difference between mine and yours is imagecopy() vs. imagecopyresampled(). I seem to remember having problems with that though it was quite a while ago. You can see an example of an image I use this pattern on here: http://www.ipnow.org/images/1/bggrad/bg4/yes/TRANSIST.TTF/8B0000/custombrowserimage.jpg (I allocate a blank image, copy the background image in, copy the overlay with transparency in)

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.