Given a File ID (fid) how can I get the HTML that represents that fid?
This works for me. For videos via the media module:

&lt;?php
  $file = file_load($fid);
  if (strpos($file-&gt;filemime, 'video/') !== 0) {
    return;
  }
  $key = 'media_' . substr($file-&gt;filemime, 6) . '_video';
  $formatter_info = file_info_formatter_types($key);
  $content = array();
  $content['#theme'] = $key;
  $content['#uri'] = $file-&gt;uri;
  if (isset($formatter_info['default settings'])) {
    $content['#options'] = $formatter_info['default settings'];
  }

  $rendered = drupal_render($content);
  return $rendered;
?&gt;


And for images; this shows you what presets are available (#style_name)

&lt;?php
$styles = image_styles();
echo '&lt;pre&gt;' . print_r($styles, TRUE) . '&lt;/pre&gt;';
?&gt;


And this will render the file

&lt;?php
$file = file_load($fid);
$image = image_load($file-&gt;uri);
$content = array(
  'file' =&gt; array(
    '#theme' =&gt; 'image_style',
    '#style_name' =&gt; 'large',
    '#path' =&gt; $image-&gt;source,
    '#width' =&gt; $image-&gt;info['width'],
    '#height' =&gt; $image-&gt;info['height'],
  ),
);
echo drupal_render($content);
?&gt;


Note that image_load performs I/O.

And for the reverse; given a filename get a fid.

&lt;?php
$query = new EntityFieldQuery();
$result = $query
  -&gt;entityCondition('entity_type', 'file')
  -&gt;propertyCondition('filename', basename($filename))
  -&gt;execute();
foreach ($result['file'] as $values) {
  $fid = $values-&gt;fid;
  break;
}
echo $fid
?&gt;


Given media embed code, get a FID.

&lt;?php
$file = media_parse_to_file($embed_code);
if (empty($file-&gt;fid)) {
  return FALSE;
}
return $file-&gt;fid;
?&gt;