Getting thumbnail dimensions on server

I've been trying to figure out how to determine the dimensions of the thumbnails on the server. I know how to figure it out on the client side with javascript, but I would much rather do my work server side.

The closest I've gotten is using show_file_metadata() to get the original file dimensions, but even this has been unsatisfactory—I can only get the dimensions as part of a large and cumbersome array or string, and have been unable to use item_file() to get at the same data.

The settings for Omeka let you specify the _max_ dimensions, so you at least have an upper bound there. The default is 200px I think, so it's fairly rare to have a thumbnail that is smaller than that, but could certainly happen.

Off the top of my head, I don't know of better ways with Omeka's functions to get that info, but there's a fair chance that some other PHP library like GD or ImageMagick is available and could help dig up that information.

Thanks, Patrick,

There are actually lots of thumbnails with at least one dimension smaller than the _max_dimensions. In fact, the only time a thumbnail will have dimensions of exactly _max_dimensions x _max_dimensions is if the original image were square. In all other cases either the height or the width will be less.

I would be happy to use ImageMagick or a PHP library to find the dimensions, but for that I believe I would need the physical path to the files to do that. Is there a reliable way to find these paths? Or is there an easier way?

If you have a File object, this should give you the path:

$path = $file->getPath('thumbnail');

Thanks, Patrick,

I tried $path = get_current_file()->getPath('thumbnail'); inside a file loop (with while(loop_files_for_item())) but I got the error "Cannot get the local path for a stored file".

oops. my bad. should have said getStoragePath('thumbnail') instead of getPath

Thanks, that works! Unfortunately, the path isn't relative to my php file, but to, I presume, the archive folder. How can I get it's path? And will working with paths like this cause problems for folks using other storage models? (It's not a big deal for us if it does, but I'd like to know.)

You can use the FILES_DIR constant to put it together:

$full_path = FILES_DIR . '/' . $path;

I'm pretty sure that it will work for other storage models.

Thanks, that pointed me in the right direction. I'm running Omeka Version 1.5.3, so I had to use ARCHIVE_DIR instaed of FILES_DIR, but once I figured that out, it all worked!

This will definitely not work for sites using any storage system other than the default Filesystem one.

Ah, too bad. We have no plans to use another system here, but it would be nice if we could eventually share our theme without that having to be a restriction.

Would it be possible for Omeka to provide an API for thumbnail sizes in a future version? It's really very useful for themes that use AJAX. (Our new theme is still a work in progress, but I'm very happy with it so far.)