How do I link an image to a given URL?
you can load a image from a node.  

 $prev_node = node_load($prev-&gt;nid); 
    $image = field_get_items('node', $prev_node, 'field_image');
     $img = field_view_value('node', $prev_node, 'field_image', $image[0], array(
      'type' =&gt; 'image',
      'settings' =&gt; array(
      'image_style' =&gt; 'thumbnail',
      'image_link' =&gt; 'content',
     ),
   ));


then if you get the image, linking image to a certain url can be easily done by

 $options = array(
            'html' =&gt; TRUE,
            'attributes' =&gt; array(
                'title' =&gt; $prev_node-&gt;title
            )
 );     
 $output = l($img, "your url", $options);
 print render($output);