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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:52:10+00:00 2026-05-20T00:52:10+00:00

GD seems to have various imagecreatefrom_x_ functions which is great if you know the

  • 0

GD seems to have various imagecreatefrom_x_ functions which is great if you know the image type ahead of time. In my particular situation, I don’t. Is there a way to read in the image without knowing the type?

My only option so far is to save it to disk (expensive!) and then use getimagesize (which also provides mime type) – but this results in me reading in the image twice – once to determine the MIME type and then again to read it into GD.

Alternatively, is it possible to just treat a variable as a file? something like this:

$image = file_get_contents('http://the.remote.file.com/myfile');

# doesn't work with already read in image ... can I treat this as a file w/o saving it?
$info = getimagesize($image);
  • 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-20T00:52:11+00:00Added an answer on May 20, 2026 at 12:52 am

    You can use imagecreatefromstring(), which is indifferent to the actual file format and the best option if you’ve read in the file already.

    But for practical purposes you should be able to use getimagesize($filename). You don’t have to read in the file before. Just use the filename or url.

    print_r(
       getimagesize("http://sstatic.net/stackoverflow/img/sprites.png?v=2")
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So various iterations of this question seems to have been asked on this site
I have various binary file formats which I need to dump to some kind
Nobody seems to have tied together all of the example code in various StackOverflow
I have my own classes that represent image data. They have various underlying structure
I have a specific css class styled which gives glass effect to the various
I am quantitatively studying various metrics associated with automated tests. Chrome seems to have
I have an issue which seems to have been reported here: Need razor view
This seems to have been asked before: rails decimal precision and scale But when
PowerBuilder seems to have some support for plug-ins since version 10. However, I can't
I have an curious zombie bug that seems to have crept out of the

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.