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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:29:05+00:00 2026-05-22T01:29:05+00:00

try{ $src = imagecreatefromjpeg(‘https://graph.facebook.com/’.$jsonfriends[data][$randf][id].’/picture’); } catch (Exception $z){ $src = imagecreatefromgif(‘https://graph.facebook.com/’.$jsonfriends[data][$randf][id].’/picture’); } In the

  • 0
try{
  $src = imagecreatefromjpeg('https://graph.facebook.com/'.$jsonfriends["data"][$randf]["id"].'/picture');
} catch (Exception $z){
  $src = imagecreatefromgif('https://graph.facebook.com/'.$jsonfriends["data"][$randf]["id"].'/picture');
}

In the above code, when the code in the ‘try’ block fails, the control is not passing to the ‘catch’ block. I’m getting output as error as https://graph.facebook.com/xxxxxx/picture is not a valid JPEG. Actually, if its not a JPEG, it would be GIF in this context. So can anyone help me regarding this?

  • 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-22T01:29:06+00:00Added an answer on May 22, 2026 at 1:29 am

    imagecreatefromjpeg doesn’t throw an exception if it fails. For more information on that, see PHP: How to manage errors gracefully?.

    You’d be better off using a function mentioned in the comments of the PHP documentation of the function:

    function open_image ($file) {
        $size = getimagesize($file);
        switch($size["mime"]){
            case "image/jpeg":
                $im = imagecreatefromjpeg($file); //jpeg file
                break;
            case "image/gif":
                $im = imagecreatefromgif($file); //gif file
                break;
            case "image/png":
                $im = imagecreatefrompng($file); //png file
                break;
            default: 
                $im=false;
                break;
        }
        return $im;
    }
    

    This way, you avoid the problem altogether, as it simply doesn’t try to parse the file as a JPEG if it isn’t one.

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

Sidebar

Related Questions

try { ... } catch (SQLException sqle) { String theError = (sqle).getSQLState(); ... }
How to install source rpm(src.rpm) in fedora? When i try to rebuild spec file
In my python app I try to open a https url, but I get:
I've written this HAML: %script{:src => http://www.google.com/jsapi?key=mykey :type => text/javascript} Note the missing comma
when I try to run my project on Jetty I get this exception: java.lang.ClassNotFoundException:
I try to get all user photo by using FQL (Facebook C# SDK, ASP
Whenever I try to disconnect the user from my website that uses the Facebook
I try: git mv a.py b.py src/ and get fatal: multiple sources for the
I'm using jQuery to update an image source $(#myImage).attr(src, imagePath); Immediately after, I try
Try loading this normal .jpg file in Internet Explorer 6.0. I get an error

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.