Add WebP thumbnail endpoint for MLS property images
- Create MLS_Image_Endpoint class with on-demand thumbnail generation
- Use ImageMagick to convert images to WebP format
- Thumbnail sizes: 800px (thumb) and 1800px (full), maintain aspect ratio
- Only downsize images, never upsize
- Cache thumbnails in wp-content/uploads/mls-thumbnails/
- Add mls_get_image_url() helper function (1-based index)
- Update property cards to display thumbnail as background-cover image
- Long cache headers (1 year) with ETag support
URL format: /mls-image/{listing_key}/{index}/{size}/
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -52,6 +52,7 @@ final class MLS_Plugin {
|
||||
private $api_client;
|
||||
private $sync_engine;
|
||||
private $media_handler;
|
||||
private $image_endpoint;
|
||||
private $query;
|
||||
|
||||
/**
|
||||
@@ -84,6 +85,7 @@ final class MLS_Plugin {
|
||||
require_once MLS_PLUGIN_DIR . 'includes/class-mls-api-client.php';
|
||||
require_once MLS_PLUGIN_DIR . 'includes/class-mls-sync-engine.php';
|
||||
require_once MLS_PLUGIN_DIR . 'includes/class-mls-media-handler.php';
|
||||
require_once MLS_PLUGIN_DIR . 'includes/class-mls-image-endpoint.php';
|
||||
require_once MLS_PLUGIN_DIR . 'includes/class-mls-query.php';
|
||||
|
||||
// Activation/Deactivation
|
||||
@@ -126,6 +128,8 @@ final class MLS_Plugin {
|
||||
$this->rate_limiter = new MLS_Rate_Limiter($this->db);
|
||||
$this->api_client = new MLS_API_Client($this->options, $this->rate_limiter, $this->logger);
|
||||
$this->media_handler = new MLS_Media_Handler($this->db, $this->logger);
|
||||
$this->image_endpoint = new MLS_Image_Endpoint($this->media_handler, $this->logger);
|
||||
$this->image_endpoint->init();
|
||||
$this->sync_engine = new MLS_Sync_Engine(
|
||||
$this->db,
|
||||
$this->api_client,
|
||||
@@ -206,6 +210,13 @@ final class MLS_Plugin {
|
||||
return $this->media_handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Image Endpoint instance
|
||||
*/
|
||||
public function get_image_endpoint() {
|
||||
return $this->image_endpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Query instance
|
||||
*/
|
||||
@@ -359,3 +370,21 @@ function mls_get_cache_stats() {
|
||||
}
|
||||
return $plugin->get_media_handler()->get_cache_stats();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get WebP thumbnail URL for a listing image
|
||||
*
|
||||
* Returns a URL to the WebP thumbnail endpoint which will:
|
||||
* - Fetch the image from MLS Grid if not cached
|
||||
* - Convert to WebP format using ImageMagick
|
||||
* - Resize to requested dimension (800px thumb or 1800px full)
|
||||
* - Cache the result for future requests
|
||||
*
|
||||
* @param string $listing_key The listing key
|
||||
* @param int $index Image index (1-based, default: 1 for primary image)
|
||||
* @param string $size 'thumb' (800px) or 'full' (1800px), default: 'thumb'
|
||||
* @return string Image URL
|
||||
*/
|
||||
function mls_get_image_url($listing_key, $index = 1, $size = 'thumb') {
|
||||
return MLS_Image_Endpoint::get_url($listing_key, $index, $size);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user