That code should get the attachments as array which you should be able to use count()
on to determine the total number of images. Example:
if ( $attachments ) {
if ( 1 == count( $attachments ) ) {
// handle single image
} else {
// handle multiple images
}
}