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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:59:10+00:00 2026-05-28T03:59:10+00:00

I have a scenario where a user uploads an image file. I strip the

  • 0

I have a scenario where a user uploads an image file. I strip the background color (defined as the upper left corner’s color)…and save to file with imagepng.

I originally tried echoing some html that directly called that file name, but it would take as long as seven minutes for the image to appear (this is a 6k file, nothing fancy). I read that you should not try to use the posted data in the same request, so, instead of outputting the image, I changed it to a link to a second page, which would get the image.

But the same lag occurs. I have not done much image manipulation, so appreciate any guidance as where I’ve gone wrong, or ways to speed things up. My eventual goal is that the user might be uploading 10+ images at a time

Here’s the primary code, the viewing_page.html was just <img src="target.png"/>

<?php
if($_FILES['test']['tmp_name']){
    //some validation is necessary, this is just a proof of concept for a friendly user test
    if($_FILES['test']['type']=="image/png"){
        $im = imagecreatefrompng($_FILES['test']['tmp_name']);
    }
    if(($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")){
        $im = imagecreatefromjpeg($_FILES['test']['tmp_name']);
    }
    if($_FILES['test']['type']=="image/gif"){
        $im = imagecreatefromgif($_FILES['test']['tmp_name']);
    }
    //determine background RGB
    $rgb = imagecolorat($im, 0, 0);
    $r = ($rgb >> 16) & 0xFF;
    $g = ($rgb >> 8) & 0xFF;
    $b = $rgb & 0xFF;
    $background = imagecolorallocate($im, $r, $g, $b);
    // Make the background transparent
    imagecolortransparent($im, $background);
    imagepng($im,'target.png');
    imagedestroy($im);
    echo "<a href=\"viewing_page.html\">View</a>";
    //echo "<img src=\"target.png\"/>"; //-----------this was my first (and preferred) approach
    }
else{
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body bgcolor="#00CCFF">
    <form action="" method="post" enctype="multipart/form-data">
    <input name="test" type="file" />
    <input type="submit" value="Submit" />
    </form>
    </body>
</html>
    <?php
}
?>
  • 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-28T03:59:11+00:00Added an answer on May 28, 2026 at 3:59 am

    Does imagepng really take so long to generate the .png file or does your web server not serve the image until it has 7 minutes of age? On my system (Linux, PHP 5.3.6) and with your code the image is available immediately.

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

Sidebar

Related Questions

I have a scenario wherein the user uploads a file to the system. The
I have an image that belongs_to a user and to a binary (physical file
I have scenario to use the Temporary user defined type variable in transaction, but
I have a scenario where a user will upload an XML file, and I'd
I have a scenario where a user will have access to a one-time-url. When
I have a scenario where a user is emailing another user in an HTML
I have a scenario where I have to check whether user has already opened
I will like to know: I have a scenario. If a user adds a
I have the following scenario: I have various user's data stored in my database.
Consider following scenario: I have RESTful URL /articles that returns list of articles user

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.