justinholtweb/craft-spectacles
Composer 安装命令:
composer require justinholtweb/craft-spectacles
包简介
Computer-vision-powered similar-image search for Craft CMS assets.
README 文档
README
Computer-vision-powered similar-image search for Craft CMS.
Docs and support: https://craft-spectacles.com
Spectacles analyzes your asset library with a vision model, stores structured metadata and a similarity vector for each image, and exposes endpoints + Twig helpers for finding similar images. Visitors can upload an image and get back the closest matches from your library.
Requirements
- Craft CMS 5.0+
- PHP 8.2+
- An API key from one of the supported providers — or a local Ollama daemon
Installation
composer require justinholtweb/craft-spectacles ./craft plugin/install spectacles
Supported providers
Vision and embedding are configured independently — pick whichever combination suits your budget and quality bar.
| Provider | Vision | Text embedding | Image embedding | Notes |
|---|---|---|---|---|
| OpenAI | gpt-4o, gpt-4o-mini, gpt-4.1 | text-embedding-3-small / -large | — | Strong default. JSON mode is reliable. |
| Anthropic | Claude 4.x (Opus / Sonnet / Haiku) | — | — | Highest-quality descriptions. Pair with another embedder. |
| Google Gemini | gemini-2.5-flash, gemini-2.5-pro | text-embedding-004 | — | Fast and inexpensive. |
| Voyage AI | — | voyage-multimodal-3 | voyage-multimodal-3 | Best similarity results — embeds the image directly, no description-loss. |
| Ollama (local) | llava, llama3.2-vision, bakllava | nomic-embed-text, mxbai-embed-large | — | Self-hosted, no API costs, slower. |
Recommended pairings:
- Best quality: Anthropic Claude (vision) + Voyage
voyage-multimodal-3(embedding) - Best price/perf: OpenAI
gpt-4o-mini+ OpenAItext-embedding-3-small - Self-hosted: Ollama
llava+ Ollamanomic-embed-text - Strict similarity, weak descriptions OK: any vision provider + Voyage multimodal
When the embedding provider is multimodal-capable (currently only Voyage), Spectacles will embed the image bytes directly instead of embedding the text description — this captures visual features the description would lose.
Configuration
Settings live at Settings → Plugins → Spectacles. Set API keys via environment variables and reference them as $OPENAI_API_KEY, $ANTHROPIC_API_KEY, $GEMINI_API_KEY, $VOYAGE_API_KEY.
Other settings:
autoAnalyzeOnUpload— queue an analysis job whenever an image asset is saved.volumeUids— restrict analysis to specific volumes.defaultResultLimit/minSimilarityScore— search tuning.allowPublicSearch/maxVisitorUploadKb— public upload endpoint controls.
Switching providers? Different models produce vectors of different dimensions, so Spectacles only compares vectors of matching shape. After switching, click Re-index all images to regenerate embeddings.
Usage
Re-index existing assets
From the settings screen, click Re-index all images to queue a job for every image in the configured volumes. Progress is visible in the queue.
Twig
{# similar to a given asset #} {% set similar = craft.spectacles.similar(asset, 8) %} {% for row in similar %} <a href="{{ row.asset.url }}"> <img src="{{ row.asset.url({ width: 240, height: 240, mode: 'crop' }) }}"> <small>{{ row.score }} — {{ row.metadata.description }}</small> </a> {% endfor %} {# free-form text search #} {% for row in craft.spectacles.searchText('foggy mountain at sunrise') %} <img src="{{ row.asset.url }}"> {% endfor %}
Visitor upload form
Drop the included partial into any frontend template:
{% include 'spectacles/_partials/upload-form' %}
Or post to the endpoint directly:
POST /spectacles/search Content-Type: multipart/form-data Accept: application/json image=<file>
Response:
{
"analysis": {
"description": "A foggy mountain ridge at sunrise.",
"tags": ["mountain", "fog", "sunrise"],
"objects": ["mountain", "trees"],
"colors": ["pink", "blue", "gray"]
},
"results": [
{ "id": 412, "url": "...", "thumbUrl": "...", "score": 0.87, "description": "..." }
]
}
JSON for an existing asset
GET /spectacles/similar/{assetId} Accept: application/json
Architecture
spectacles_imagemetadatatable stores description, tags, objects, colors, and the embedding vector (as JSON) for each asset.- Vision and embedding are separate concerns:
services/vision/VisionProvider—analyze()returns anAnalysisResult.services/embedding/EmbeddingProvider—embedText()and optionalembedImage()returnEmbeddingResult.
services/Vision::embedForImage()prefers multimodal embedding when the provider supports it, falling back to text.- Similarity uses pluggable backends (
services/similarity/SimilarityBackend):- Scan (default): cosine in PHP over the JSON embeddings; works on any DB.
- pgvector: queries a dedicated
spectacles_imagevectorstable with thevectortype; orders of magnitude faster and lets you add an HNSW or IVFFlat index for production scale. - The active backend is auto-detected on Postgres + extension, or you can force it from the settings screen.
CP integration
The asset edit screen renders a Spectacles panel in the sidebar showing the description, tags, similar-image thumbnails, and the active backend/model. If the asset hasn't been analyzed yet, an "Analyze now" button queues a job.
Adding a provider
- Implement
VisionProviderand/orEmbeddingProviderundersrc/services/vision/orsrc/services/embedding/. - Add a constant to
Settings::PROVIDER_*and toVISION_PROVIDERS/EMBEDDING_PROVIDERS. - Wire it into
Vision::visionProvider()/Vision::embeddingProvider(). - Add fields to the settings template.
License
MIT
justinholtweb/craft-spectacles 适用场景与选型建议
justinholtweb/craft-spectacles 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 06 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cms」 「similarity」 「image search」 「Craft」 「ai」 「craftcms」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 justinholtweb/craft-spectacles 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 justinholtweb/craft-spectacles 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 justinholtweb/craft-spectacles 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
SimHash similarities algorithm implementation for PHP 5.3
PHP Interface for Babel Street Text Analytics
GraphQL authentication for your headless Craft CMS applications.
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
Set Links with a specific language parameter
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 36
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2026-06-11