chuoke/unify-gallery
Composer 安装命令:
composer require chuoke/unify-gallery
包简介
A unified bridge for multiple media sources: Unsplash, Pexels, Pixabay, Bing and more
README 文档
README
A unified bridge for multiple media sources — search photos and videos from Unsplash, Pexels, Pixabay, Bing, Wikimedia Commons, and NASA through a single consistent interface.
This package was renamed from chuoke/unify-gallery to chuoke/media-bridge in v2.
Supported Sources
| Driver | Search | Browse | API Key | Media Types |
|---|---|---|---|---|
| Bing | ✗ | ✓ | No | Photo |
| Unsplash | ✓ | ✓ | Yes | Photo |
| Pexels | ✓ | ✓ | Yes | Photo, Video |
| Pixabay | ✓ | ✓ | Yes | Photo, Video |
| Wikimedia | ✓ | ✓ | No | Photo, Video |
| NASA | ✓ | ✓ | No | Photo, Video |
Installation
composer require chuoke/media-bridge
For Laravel integration, also install:
composer require illuminate/support
Usage
Standalone
use Chuoke\MediaBridge\MediaManager; $manager = new MediaManager([ 'default' => 'unsplash', 'drivers' => [ 'unsplash' => ['api_key' => 'your-unsplash-key'], 'pexels' => ['api_key' => 'your-pexels-key'], 'pixabay' => ['api_key' => 'your-pixabay-key'], ], ]); // Search photos $result = $manager->driver('pexels')->search('mountain', page: 1, perPage: 20); // Browse without query (Bing, Wikimedia; NASA falls back to a generic feed) $result = $manager->driver('bing')->search(); // Use default driver $result = $manager->search('ocean'); foreach ($result->items as $item) { echo $item->source; // 'pexels' echo $item->url; // full image URL echo $item->thumb_url; // thumbnail URL print_r($item->variants); // available size / asset variants echo $item->author_name; // photographer name echo $item->license; // 'pexels', 'cc0', etc. }
Extra Parameters
$result = $manager->driver('pixabay')->search('forest', extras: [ 'orientation' => 'landscape', // 'landscape' | 'portrait' | 'squarish' 'color' => 'green', 'media_type' => 'video', // 'photo' | 'video' 'locale' => 'zh-CN', ]);
Media Variants
foreach ($item->variants as $variant) { echo $variant->type; // 'thumb', 'small', 'large', 'original', etc. echo $variant->url; echo $variant->width; echo $variant->height; }
Pagination
$result = $manager->driver('wikimedia')->search('', perPage: 20); if ($result->hasMore) { $next = $manager->driver('wikimedia')->search('', perPage: 20, extras: [ 'cursor' => $result->nextPage, ]); }
Most drivers return the next numeric page in nextPage. Cursor-based sources such as Wikimedia may return an opaque token array; pass it back as extras['cursor'].
Bing only exposes a shallow daily archive feed. The driver fetches the available archive batches internally, deduplicates repeated items by source_id, and then paginates the merged result locally.
MediaResult fields:
| Field | Type | Description |
|---|---|---|
items |
MediaItem[] |
Result items |
total |
int |
Total count when available |
has_more |
bool |
Whether another page is available |
page |
int |
Current numeric page |
per_page |
int |
Requested page size |
next_page |
int|string|array|null |
Next page number or cursor token |
Check Driver Capabilities
$driver = $manager->driver('bing'); $driver->source(); // 'bing' $driver->searchable(); // false — Bing does not support keyword search $driver->requiresApiKey(); // false
Laravel
If you are using a full Laravel application, the required Illuminate packages are already present.
Publish the config file:
php artisan vendor:publish --tag="media-bridge-config"
Configure your API keys in config/media-bridge.php or via environment variables:
UNSPLASH_API_KEY=your-key PEXELS_API_KEY=your-key PIXABAY_API_KEY=your-key
Use the facade:
use Chuoke\MediaBridge\Laravel\Media; $result = Media::driver('unsplash')->search('sunset'); $result = Media::search('cat'); // uses default driver
When the package runs inside a Laravel application, outgoing requests use Laravel's Http client automatically. That allows Laravel-side tooling such as Telescope to observe these requests. Outside Laravel, the package continues to use Guzzle directly.
MediaItem Fields
| Field | Type | Description |
|---|---|---|
source |
string |
Driver name, e.g. 'unsplash' |
source_id |
string |
Stable ID from the source platform |
media_type |
string |
'photo' or 'video' |
url |
string |
Best available direct media URL |
thumb_url |
string |
Thumbnail URL |
variants |
array |
Available media variants |
download_url |
string|null |
Download trigger URL (Unsplash) |
title |
string|null |
Title if provided by source |
description |
string|null |
Description if provided by source |
author_name |
string|null |
Photographer / uploader name |
author_url |
string|null |
Link to author profile |
license |
string |
License identifier, e.g. 'cc0' |
width |
int|null |
Image width in pixels |
height |
int|null |
Image height in pixels |
color |
string|null |
Dominant color hex (if available) |
tags |
array |
Keyword tags |
display_date |
string|null |
Date string YYYY-MM-DD |
Testing
composer test
The default test suite uses mocked HTTP responses and does not require API keys or network access.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.
chuoke/unify-gallery 适用场景与选型建议
chuoke/unify-gallery 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 01 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「media」 「image」 「bing」 「gallery」 「Unsplash」 「Pixabay」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 chuoke/unify-gallery 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 chuoke/unify-gallery 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 chuoke/unify-gallery 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Library for making calls to the Microsoft Translator V2 API
Search engine scrapper
Simple Sharing generates social media share links within CP entry pages, allowing you to quickly & easily share entries.
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
The Yii2 extension uses jQuery PrettyPhoto and OwlCarousel js and makes image galary from php array of structure defined.
统计信息
- 总下载量: 25
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-01-18