Minimalization approach:
function getImagesNo($path) { return ($files=glob($path.'*.jpg')) ? count($files) : 0; }