I have a Ubercart Product that is loosely linked to some data. I want to display the first image attached to that Product and I know the Node ID of the product.

$productid = SomeFunctionToGetProductID();
$node = node_load($productid);
$images = field_get_items('node', $node, 'uc_product_image');

Images is an array of the following format

[0] => Array(
  [fid] => 59
  [alt] =>
  [title] =>
  [width] => 691
  [height] => 438
  [uid] => 2
  [filename] => imagename.jpg
  [uri] => public://imagename.jpg
  [filemime] => image/jpeg
  [filesize] => 24067
  [status] => 1
  [timestamp] => 1326693866
  [type] => image
  [rdf_mapping] => Array
      (
      )

So to output this as an image of a known image type (say “thumbnail”)

$image = $images[0];
$imagedef = array(
        'style_name' => 'thumbnail',
        'path' => $image['uri'],
);
$html = theme('image_style', $imagedef);

And your done!

Leave a Reply

Your email address will not be published. Required fields are marked *