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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:21:43+00:00 2026-06-01T18:21:43+00:00

I’m attempting to add a function to my site where users can set their

  • 0

I’m attempting to add a function to my site where users can set their profile picture as an image from an external url, instead of saving it to their pc, then uploading it to my server.

This is what I’ve come up with so far:

            $filename = $inputs['image_url'];

            if(getimagesize($filename)){
                // Get new dimensions
                list($width, $height) = getimagesize($filename);
                $new_width = 100;
                $new_height = 100;

                // Resample
                $image_p = imagecreatetruecolor($new_width, $new_height);                                           

                //a check needs to be done here $image = imagecreatefromjpeg($filename);
                imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

                $filename = "profile_pictures/". md5( uniqid(rand(),true) ).".jpg";

                imagejpeg($image_p,$filename,100);
            }else{
                echo 'This is not an image';
            }

The code can download .jpg images fine, but I want to support other filetypes too.

I need to somehow check the file type of the image so I can save other images with different filetypes…

                if($extension=="jpg" || $extension=="jpeg"){
                    $image = imagecreatefromjpeg($filename);
                }else if($extension=="png"){
                    image = imagecreatefrompng($filename);
                }else{
                    $image = imagecreatefromgif($filename);
                }

Does anyone know of a function that would allow me to do this?

Thanks in advance for any replies.

  • 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-01T18:21:44+00:00Added an answer on June 1, 2026 at 6:21 pm

    Most straight forward and for GD compatiblity checking you can just create it from string:

    $image = imagecreatefromstring(file_get_contents($filename));
    

    If this fails to load, you know that you can not process that image.

    But see as well getimagesize, it inspects the filetype as well, not only width and height:

    list($width, $height, $type) = getimagesize($filename);
    

    The third element, $type, then is any of these IMAGETYPE_XXX constants:

    Value   Constant
    1     IMAGETYPE_GIF
    2     IMAGETYPE_JPEG
    3     IMAGETYPE_PNG
    4     IMAGETYPE_SWF
    5     IMAGETYPE_PSD
    6     IMAGETYPE_BMP
    7     IMAGETYPE_TIFF_II (intel byte order)
    8     IMAGETYPE_TIFF_MM (motorola byte order)
    9     IMAGETYPE_JPC
    10    IMAGETYPE_JP2
    11    IMAGETYPE_JPX
    12    IMAGETYPE_JB2
    13    IMAGETYPE_SWC
    14    IMAGETYPE_IFF
    15    IMAGETYPE_WBMP
    16    IMAGETYPE_XBM
    17    IMAGETYPE_ICO
    

    From exif_imagetype. If you combine both, you could first check if the type is okay to load for you and you then check if you can load it.

    • 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
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.