wordpress get gallery images title

In WordPress attachments are stored as posts so you can use most of the post specific WordPress calls and functions to read/write data associated with the attachment. This applies to post meta data for an attachment as well.

So in this case, since you have the post ID ( same as $attachment_id ) you can simply use the get_the_title() function:

$sImageTitle = get_the_title( $attachment_id );

This returns a string of the post’s title for the given post ID.

See more info. at the codex docs here.