How do I turn a post thumbnail into a background image?

I was looking for a code snippet that will extract the URL of a post thumbnail to be used as a background image. Through research elsewhere, the best answer I found is the code snippet below:

<div style="background: url(<?php $image_id = get_post_thumbnail_id(); $image_url = wp_get_attachment_image_src($image_id,'large', true); echo $image_url[0]; ?>)"></div>

This code sets the large thumbnail of a post as the background image in this div tag. From here I believe you should be able to modify this code to your particular situation.