This is the solution I came up with. It's definitely slow on the initial load, but once a thumbnail is saved, it's pretty fast.
I'm using the workflows.php class:
function registerResult($result) {
global $w;
$filename = 'thumbs/' . $result["objectID"] . ".jpg";
if(!file_exists($filename)) {
$image = imagecreatefromjpeg($result["thumbnail"]);
$thumb_width = 75;
$thumb_height = 75;
$width = imagesx($image);
$height = imagesy($image);
$original_aspect = $width / $height;
$thumb_aspect = $thumb_width / $thumb_height;
if ( $original_aspect >= $thumb_aspect )
{
// If image is wider than thumbnail (in aspect ratio sense)
$new_height = $thumb_height;
$new_width = $width / ($height / $thumb_height);
}
else
{
// If the thumbnail is wider than the image
$new_width = $thumb_width;
$new_height = $height / ($width / $thumb_width);
}
$thumb = imagecreatetruecolor( $thumb_width, $thumb_height );
// Resize and crop
imagecopyresampled($thumb,
$image,
0 - ($new_width - $thumb_width) / 2, // Center the image horizontally
0 - ($new_height - $thumb_height) / 2, // Center the image vertically
0, 0,
$new_width, $new_height,
$width, $height);
imagejpeg($thumb, $filename);
}
$w->result(
$result["name"],
$result["objectID"] . "---" . $result["canonicalUrl"] . "---" . $result["state"],
$result["name"],
$result["objectID"] . " - " . $result["state"] . isset($result["prices"]) ? " - " . money_format('$%i', $result["prices"]["final"]) : "",
$filename
);
return;
}