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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:37:26+00:00 2026-05-13T08:37:26+00:00

I am trying to build a class that does many photo operations, one method

  • 0

I am trying to build a class that does many photo operations, one method will upload images from a user but I am also needing to build a method to grab a photo from a URL and run other methods on it just like if it were being uploaded with a POST form from user.

Below is my start of the function for getting image from URL, it works but needs work still. Below the code you can see a image that is the result of this function being ran. Also is the original image to see what it should look like. You can see that this function makes the image have a black background on this transparent image. How can I make it look better like it should look?

$url = 'http://a0.twimg.com/a/1262802780/images/twitter_logo_header.png';

//run our function
savePhotofromURL($url, 'no');



// photo function should grab an photo from a URL
function savePhotofromURL($photo_url, $saveimage = 'yes'){
    if(isset($photo_url) && $photo_url != '') {

        //get info about photo
        $photo_info = getimagesize($photo_url);
        $source_width = $photo_info['0'];
        $source_height = $photo_info['1'];
        $source_type = $photo_info['mime'];

        //grab the Photo from URL
        $photo = imagecreatefromstring(file_get_contents($photo_url));

        if (is_resource($photo) === true){
            if($saveimage === 'yes'){
                // TO DO: resize image and make the thumbs code would go here if we are saving image:
                // TO DO: resize source image if it is wider then 800 pixels
                // TO DO: make 1 thumbnail that is 150 pixels wide
            }else{
                // We are not saving the image show it in the user's browser
                // TO DO: we will add in correct photo type soon
                header('Content-Type: image/gif');
                imagejpeg($photo, null, 100);
                imagedestroy($photo); 
            }
        }else{
            // not a valid resource, show error
            echo 'error getting URL photo from ' .$photo_url;
        }
    }else{
        // url of image was empty
        echo 'The URL was not passed into our function';
    }
}

The result looks like this
alt text http://img2.pict.com/52/05/1f/2429493/0/screenshot2b181.png

Instead of like this
alt text

  • 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-13T08:37:27+00:00Added an answer on May 13, 2026 at 8:37 am

    The following two calls will tell php to use the alpha blending present in the png image:

            ImageAlphaBlending($photo, false);
            ImageSaveAlpha($photo, true);
    

    Edit:
    I see you’re outputting the image as a JPEG also. JPEGs don’t support transparency, so no matter what you do you will end up with an incorrect background color. Also see this related question: PHP/GD ImageSaveAlpha and ImageAlphaBlending

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

Sidebar

Ask A Question

Stats

  • Questions 290k
  • Answers 290k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer My advice is to avoid this general design altogether. Don't… May 13, 2026 at 5:51 pm
  • Editorial Team
    Editorial Team added an answer http://code.google.com/p/procname/ Sample usage: # Lets rename: >>> procname.setprocname('My super name')… May 13, 2026 at 5:51 pm
  • Editorial Team
    Editorial Team added an answer When the Gem is loaded, Rails first looks for a… May 13, 2026 at 5:51 pm

Related Questions

I'm trying to build a modified role system that has the following class/relationship structure:
Versions Excel 2007, Windows Vista, VB.NET, Visual Studio 2008 with .NET 3.5 sp2, MSI
I am trying to build an ASP.NET 3.5 website that allows users to log
EDIT: I am basically running into the following documented issue . I am using
I am trying to build a site with news links that can be voted,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.