well i thought that was integrated in browseimages....
at the bottom of a browseimage page you have:
display options where you can sort by rating...
it adds '&orderby=rating&direction=DESC' to the query string...
this meens that you just have to add
$orderby = 'rating';
$direction = 'DESC';
in the code...
add it after the vars are cleaned..
$postid = $vbulletin->input->clean_gpc('r', 'postid', TYPE_NOHTML);
that should work..