I am trying to catch the following error due to imagecreatefromjpeg function.
Corrupt JPEG data: premature end of data segment
I don't want to display this error in the output of my PHP script so I try to use ob_start and ob_get_contents but it doesn't work. The goal is to catch this error to know which images are corrupted.
Here is my code :
ob_start();
$img = imagecreatefromjpeg($imgDestinationPath);
$output = ob_get_contents();
echo "test";
ob_end_clean();
if( $output == "Corrupt JPEG data: premature end of data segment" )
{
$this->log("The following image is corrupted : $imgDestinationPath");
}
var_dump($output);
Output :
Corrupt JPEG data: premature end of data segment string(4) "test"
Corrupted image :
Any ideas as to why I am not getting imagecreatefromjpeg output in the buffer?