If you don't sure whether the file exists or not or maybe it's broken, then you should use try - catch construction. It prevents code fails, when code stops execution after call of pingImage (if the file doesn't exist or it's broken).
<?php
$im = new Imagick();
try {
$im->pingImage('3.jpg');
}
catch(ImagickException $e) {
echo "image doesn't exist";
}
?>