Collection thumbnail URI

Is there a way to get the URI of the thumbnail for a collection?

Using record_image will give me file mark up, but I only want the address of the image (preferably being able to specify the image size, as I can with file metadata).

Here's bits that record_image ultimately does before producing markup, slightly modified from the Omeka_View_Helper_FileMarkup.php file

$file = $record->getFile();
$uri = $file->getWebPath($format);

$record would be the collection object in this case, and $uri is what you're looking for. $format is the derivative image type ('thumbnail', 'square_thumbnail', etc).

This leaves out the checks for whether there really is a file for the record, and whether there is a derivative image, but this should get the basics going.

That looks good - but there is an issue.

I am looping over collections, and the second time round I am getting an error:

Fatal error: Call to a member function getWebPath()

There could be a couple things at work.

First, is that the loop might be hitting a collection that doesn't have a representative file. In that case, I'm guessing that the rest of the error is something like on non object?

Second, the loop might not be digging up the collection object right for that code. Something like

$record = get_current_record('collections');

might get what you need.

Either way, if you post up the code you are using for the loop and digging up the uri that'll help find the problem.

There were no items with images added to one of the collections I was looping over, which was causing the error.

I added a quick check to avoid the error and set a different value:

$file = $collection->getFile();
$uri = (!$file) ? 'No image' : $file->getWebPath('square_thumbnail');