Post Thumbnails without custom field

I encounter situations where i need to automatically display a thumbnail or image of Books that will link to posts. Now i found the solution to display Thumbnails without custom field.  Here’s an example of this kind of situation:

Write the given code in functions.php

function getImage($num) {
global $more;
$more = 1;
$link = get_permalink();
$content = get_the_content();
$count = substr_count($content, ‘<img’);
$start = 0;
for($i=1;$i<=$count;$i++) {
$imgBeg = strpos($content, ‘<img’, $start);
$post = substr($content, $imgBeg);
$imgEnd = strpos($post, ‘>’);
$postOutput = substr($post, 0, $imgEnd+1);
$result = preg_match(‘/width=”([0-9]*)” height=”([0-9]*)”/’, $postOutput, $matches);
if ($result) {
$pagestring = $matches[0];
$image[$i] = str_replace($pagestring, “”, $postOutput);
} else {
$image[$i] = $postOutput;
}
$start=$imgEnd+1;
}
if(stristr($image[$num],'<img’)) { echo ‘<a href=”‘.$link.'”>’.$image[$num].”</a>”; }
$more = 0;
}

Code for calling thumb img

<?php getImage(‘1’); ?>

(“1” 1st image in the post…)