Filters the_post_thumbnail() function. If no post thumbnail is defined, get the first image belonging to post or first image found in post content.
add_theme_support('post-thumbnails');in the functions.php file of your theme.
the_post_thumbnail($size, $attr)in the loop in your template where you want the post image to appear. For example :