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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:56:40+00:00 2026-05-25T14:56:40+00:00

I am simply trying to return an PNG image through PHP, but I have

  • 0

I am simply trying to return an PNG image through PHP, but I have a problem with the transparency not showing right. (Basically one PHP file will be capable of returning any of my images.)

I use simple code to return the image:

<?php
    $im = imagecreatefrompng("images/fakehairsalon.png");
    header('Content-Type: image/png');
    imagepng($im);
    imagedestroy($im);
?>

The original image looks like this:
Original image

And the one returned via PHP (and that piece of code) looks like this:
Messed up image

Is there anything I can do to prevent this and make the image come through normal?

  • 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-25T14:56:41+00:00Added an answer on May 25, 2026 at 2:56 pm

    As explained in a user comment, you must do this:

    <?php
    $im = imagecreatefrompng("borrame.png");
    header('Content-Type: image/png');
    
    imagealphablending($im, true); // setting alpha blending on
    imagesavealpha($im, true); // save alphablending setting (important)
    
    imagepng($im);
    imagedestroy($im);
    ?>
    

    Update: This answer was assuming that your code is an except from a bigger script you are using to do on-the-fly image manipulation.

    If you don’t want to change the original file, this is a plain waste of memory and CPU cycles. You can use file system functions to read it as a regular file, such as readfile().

    It’s also worth noting that using PHP to deliver a file only makes sense if you want to do something else as well, such as:

    • Restricting access to the file
    • Keeping a counter
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm simply trying to crop a JPEG image (no scaling) using PHP. Here is
I'm trying to simply place an image, dotpowder.png , where you touch the screen.
I'm trying to get multipass texturing work for me but right now i can
This has got to be obvious but I'm just not seeing it. I have
I'm trying to perform a simple INSERT and return the identity (auto-incrementing primary key).
I'm simply trying to create a UML diagram where I can show the header
I'm simply trying to convert a CGEventTimestamp (which is an unsigned 64-bit integer roughly
I am simply trying to draw a rectangle inside of a panel using flex4.
I am simply trying to display a users location on a map, I am
Is there a better way than simply trying to open the file? int exists(const

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.