Jump to content


Photo

how to detect invalid jpeg format ?


  • Please log in to reply
4 replies to this topic

#1 miob

miob
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 26 April 2006 - 09:40 PM

i do resize on some external jpegs, but sometimes i get 404 error page instead of jpeg,
but script copied it , saved it and if i do resize i get black square from it.
i have no clue how to stop resizing , or do anything with no picture,
how to detect if it's case where is no pic.

getimagesize doesn't help for me...

thanx

#2 DepretioN

DepretioN
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 26 April 2006 - 09:56 PM


function is_jpeg($image)
{
    $image_mime_type = mime_content_type($image);

    if (("image/jpeg" == $image_mime_type) || ("image/jpg" == $image_mime_type))
         return true;
    else
        return false;
}


#3 koencalliauw

koencalliauw
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 26 April 2006 - 09:56 PM

Could you give us some code to get a better understanding of what you're doing?

Koen.

#4 koencalliauw

koencalliauw
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 26 April 2006 - 09:58 PM

to previous function: maybe add an if(file_exists($image)) too.

#5 miob

miob
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 27 April 2006 - 12:20 AM

Fatal error: Call to undefined function: mime_content_type()

i have noticed that it happens when instead of jpeg they have 404 redirect to some html page, copy function copied it as binary file, and result is that it has nothing to do with jpeg format.

is there any chance to get it fixed without changing of php.ini ?

then i've found this

if ( ! function_exists ( 'mime_content_type ' ) )
{
function mime_content_type ( $f )
{
return system ( trim( 'file -bi ' . escapeshellarg ( $f ) ) ) ;
}
}

by adding this next function all sounds fine..




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users