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 8229969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:58:36+00:00 2026-06-07T16:58:36+00:00

There is an image which has transparent area. (png image) Now, while doing a

  • 0

There is an image which has transparent area. (png image)
Now, while doing a imagecopy, can we just fill that transparent area?

Imagemagick can do this easily. Is that possible in php gd?

  • 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-06-07T16:58:39+00:00Added an answer on June 7, 2026 at 4:58 pm

    A layered approach via imagecopymerge() is one route. The concept is to merge your source image onto a new image, with a pre-set background image, which will show through the source image’s transparency once merged.

    //create main image - transparent, with opaque red square in middle
    $img = imagecreate(60, 60);
    $white = imagecolorallocate($img, 255, 255, 255);
    imagecolortransparent($img, $white); //make background transparent
    $red = imagecolorallocate($img, 255, 0, 0);
    imagefilledrectangle($img, imagesx($img) / 4, imagesy($img) / 4, imagesx($img) - (imagesx($img) / 4), imagesy($img) - (imagesy($img) / 4), $red);
    
    //create new image, with pre-filled background, then merge first image across
    $img2 = imagecreate(60, 60);
    $blue = imagecolorallocate($img2, 0, 0, 255);
    imagecopymerge($img2, $img, 0, 0, 0, 0, imagesx($img), imagesy($img), 100);
    
    //output
    imagepng($img2);
    

    So the first image creates a transparent image (the white) with a red square in the middle. The second image is simply a blue fill.Merge the two, and the blue shows through the transparent part of the first image, so our red square now sits on the blue fill. Effectively, we’ve filled the transparent part.

    Here’s the three states in sequence.

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

Sidebar

Related Questions

When using a transparent PNG image which has a fine fading shadow always there
In the image below there is an area, which has an unknown (custom) class.
Is there a PHP function which can accept the image path of a PNG-24
In an image there is a face, which is tilted a bit and has
I have an image which has a relatively large area of transparency, alpha space.
These are the three ways in which the same image has been referenced to
Is there any curve control in pyqt?, I have attached a image which is
Are there any existing add-ons which would provide the functionality Upload image from local
There is a task to display an image, which is placed to a Google
I have created custom cell in which there are n number of image views.

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.