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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:22:56+00:00 2026-05-28T02:22:56+00:00

I have a PHP function below that is used for a command line tool

  • 0

I have a PHP function below that is used for a command line tool for optimizing images, in the function below it is running ImageMagick on all files passed to it and getting the file extension.

I have only tested it on actual image files until tonight. I tested on a folder with images and other files mixed in.

The result is an error like this…

identify.exe: no decode delegate for this image format  
`E:\Server\img\testfiles\archive.php' @ error/constitute.c/ReadImage/532.

Now I know it is kind of hard to filter the non-image files out when this function is specifically for the purpose of determining that value….But is there a better way that I can handle this situation, if a non-image file is passed through my program to this function, can I suppress the errors or avoid them from happening?

The function…

/**
 * is_image 
 * @param mixed $file_path 
 * @static
 * @access public
 * @return void
 */
public static function is_image($file_path)
{
    if (!file_exists($file_path)) {
        throw new FileNotFoundException("File or path not found: " . $file_path);
    }
    $types = array("gif", "png", "gifgif", "jpg", "jpeg", "bmp");

    //exec("/usr/bin/identify -quiet -format \"%m\" $file_path", $return, $error);
    $imagemagick = self::$program_paths['imagemagick'] . '\identify';
    exec($imagemagick . ' -quiet -format %m ' . $file_path, $return, $error);

    $type = ($error === 0) ? mb_strtolower($return[0]) : "";
    if ($error == 1) {
        return false;
    }
    if (substr($type, 0, 6) === "gifgif") {
        $type = "gifgif";
    }
    return in_array($type, $types);
}
  • 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-28T02:22:56+00:00Added an answer on May 28, 2026 at 2:22 am

    Use the fileinfo functions to determine whether or not it’s an image first.

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

Sidebar

Related Questions

I have a php function that generates HTML code like below function j_uf_SomeFunction($some_var) {
Below is an old PHP function I have for a dropdown list for users
I have a php function I wrote that will take a text file and
I have a PHP function that takes a variable number of arguments (using func_num_args()
I have a PHP function that requires can take 3 parameteres... I want to
Is it possible to have a PHP function that is both recursive and anonymous?
I have written a PHP function to take a video embed code that has
I have the following Regex used to match PHP Class, method and Function names
i have a php function which returns a random json encoded color <?php function
I'm not very good at PHP and would like to have a PHP function

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.