ghanem/giphy
Composer 安装命令:
composer require ghanem/giphy
包简介
A package that provides an interface between Laravel and Giphy API, includes Gifs.
README 文档
README
A package that provides an interface between Laravel and Giphy API, includes Gifs and Stickers.
Installation
You can install the package via composer:
composer require ghanem/giphy
now you need to publish the config file with:
php artisan vendor:publish --provider="Ghanem\Giphy\GiphyServiceProvider" --tag="config"
Parameters
- q - search query term or phrase
- s - search query term or phrase
- limit - (optional) number of results to return, maximum 100. Default 25.
- offset - (optional) results offset, defaults to 0.
- rating - (optional) limit results to those rated (y,g, pg, pg-13 or r).
- lang - (optional) specify default country for regional content; format is 2-letter ISO 639-1 country code. See list of supported langauges here
Endpoints
Gifs
Search
Search all Giphy GIFs for a word or phrase. Punctuation will be stripped and ignored. On this case, $giphys is an array.
Method: Giphy::search($query, $limit = 25, $offset = 0, $rating = null, $lang = null)
$giphys = Giphy::search('cat'); foreach ($giphys->data as $giphy) { // Get id $giphy->id; // Get image original url $giphy->images->original->url; // Get image original mp4 url $giphy->images->original->mp4; //etc }
You can do a dd($giphys) to see all attributes:
{#162 ▼
+"data": array:25 [▼
0 => {#163 ▼
+"type": "gif"
+"id": "W80Y9y1XwiL84"
+"slug": "gift-W80Y9y1XwiL84"
+"url": "http://giphy.com/gifs/gift-W80Y9y1XwiL84"
...
}
1 => {#182 ▶}
2 => {#202 ▶}
...
Translate
The translate API draws on search, but uses the Giphy "special sauce" to handle translating from one vocabulary to another.
Method: Giphy::translate($query, $rating = null, $lang = null)
$giphy= Giphy::translate('cat'); // Get id $giphy->data->id; // Get image original url $giphy->data->images->original->url; // Get image original mp4 url $giphy->data->images->original->mp4; //etc
You can do a dd($giphy) to see all attributes:
{#162 ▼
+"data": {#163 ▼
+"type": "gif"
+"id": "3oz8xQQP4ahKiyuxHy"
...
+"images": {#165 ▼
...
+"original": {#180 ▼
+"url": "http://media3.giphy.com/media/3oz8xQQP4ahKiyuxHy/giphy.gif"
+"width": "480"
+"height": "352"
+"size": "3795005"
+"frames": "33"
+"mp4": "http://media3.giphy.com/media/3oz8xQQP4ahKiyuxHy/giphy.mp4"
+"mp4_size": "132229"
+"webp": "http://media3.giphy.com/media/3oz8xQQP4ahKiyuxHy/giphy.webp"
+"webp_size": "756840"
}
...
Trending
Fetch GIFs currently trending online. On this case, $giphys is an array.
Method: Giphy::trending($limit = 25, $rating = null)
$giphys = Giphy::trending(); foreach ($giphys->data as $giphy) { // Get id $giphy->id; // Get image original url $giphy->images->original->url; // Get image original mp4 url $giphy->images->original->mp4; //etc }
You can do a dd($giphys) to see all attributes:
{#162 ▼
+"data": array:25 [▼
0 => {#163 ▼
+"type": "gif"
+"id": "l2SqiAELInKQ8rF0Q"
+"slug": "2dopequeens-podcast-2-dope-queens-l2SqiAELInKQ8rF0Q"
+"url": "http://giphy.com/gifs/2dopequeens-podcast-2-dope-queens-l2SqiAELInKQ8rF0Q"
...
}
1 => {#183 ▶}
2 => {#203 ▶}
...
Random
Returns a random GIF, limited by tag.
Method: Giphy::random($query, $rating = null)
$giphy = Giphy::random('cat'); // Get id $giphy->data->id; // Get image original url $giphy->data->image_original_url; // Get image mp4 url $giphy->data->image_mp4_url; //etc
You can do a dd($giphy) to see all attributes:
{#162 ▼
+"data": {#163 ▼
+"type": "gif"
+"id": "qbpRDgYI5JoKk"
+"url": "http://giphy.com/gifs/cat-qbpRDgYI5JoKk"
+"image_original_url": "https://media0.giphy.com/media/qbpRDgYI5JoKk/giphy.gif"
...
}
+"meta": {#164 ▼
+"status": 200
+"msg": "OK"
}
}
By ID
Returns meta data about a GIF, by GIF id.
Method: Giphy::getByID($id)
$giphy= Giphy::getByID('qbpRDgYI5JoKk'); // Get id $giphy->data->id; // Get image original url $giphy->data->images->original->url; // Get image original mp4 url $giphy->data->images->original->mp4; //etc
You can do a dd($giphy) to see all attributes:
{#162 ▼
+"data": {#163 ▼
+"type": "gif"
+"id": "qbpRDgYI5JoKk"
...
+"images": {#164 ▼
...
+"original": {#179 ▼
+"url": "https://media1.giphy.com/media/qbpRDgYI5JoKk/giphy.gif"
+"width": "500"
...
By IDs
A multiget version of the get GIF by ID endpoint. On this case, $giphys is an array.
Method: Giphy::getByIDs(array $ids)
$giphys = Giphy::getByIDs(['qbpRDgYI5JoKk','FiGiRei2ICzzG']); foreach ($giphys->data as $giphy) { // Get id $giphy->id; // Get image original url $giphy->images->original->url; // Get image original mp4 url $giphy->images->original->mp4; //etc }
You can do a dd($giphys) to see all attributes:
{#162 ▼
+"data": array:2 [▼
0 => {#163 ▼
+"type": "gif"
+"id": "qbpRDgYI5JoKk"
+"slug": "cat-qbpRDgYI5JoKk"
...
}
1 => {#182 ▼
+"type": "gif"
+"id": "FiGiRei2ICzzG"
+"slug": "funny-cat-FiGiRei2ICzzG"
...
Stickers
The methods of Stickers are similar to the methods Giphy, so I will omit the examples of dd(), but also you can use it to view all the attributes of objects.
Sticker Search
Search all Sticker for a word or phrase. Punctuation will be stripped and ignored. On this case, $stickers is an array.
Method: Stickers::search($query, $limit = 25, $offset = 0, $rating = null, $lang = null)
$stickers = Stickers::search('dog'); foreach ($stickers->data as $sticker) { // Get id $sticker->id; // Get image original url $sticker->images->original->url; // Get image original mp4 url $sticker->images->original->mp4; //etc }
Sticker Translate
The translate API draws on search, but uses the Stickers "special sauce" to handle translating from one vocabulary to another.
Method: Stickers::translate($query, $rating = null, $lang = null)
$sticker= Stickers::translate('cat'); // Get id $sticker->data->id; // Get image original url $sticker->data->images->original->url; // Get image original mp4 url $sticker->data->images->original->mp4; //etc
Sticker Trending
Fetch Stickers currently trending online. On this case, $stickers is an array.
Method: Stickers::trending($limit = 25, $rating = null)
$stickers = Stickers::trending(); foreach ($stickers->data as $sticker) { // Get id $sticker->id; // Get image original url $sticker->images->original->url; // Get image original mp4 url $sticker->images->original->mp4; //etc }
Sticker Random
Returns a random Sticker, limited by tag.
Method: Stickers::random($query, $rating = null)
$sticker = Stickers::random('cat'); // Get id $sticker->data->id; // Get image original url $sticker->data->image_original_url; // Get image mp4 url $sticker->data->image_mp4_url; //etc
ghanem/giphy 适用场景与选型建议
ghanem/giphy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 466 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 07 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「api」 「laravel」 「gif」 「giphy」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ghanem/giphy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ghanem/giphy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ghanem/giphy 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Alfabank REST API integration
Zero-dependency raw PHP DNS resolver, domain-ownership verification, and intoDNS/MxToolbox-style diagnostics. Queries authoritative nameservers directly over sockets — never trusts the recursive cache for ownership checks.
Laravel package for Accurate Online API integration.
A lightweight plain-PHP framework for database-backed CRUD APIs.
bughq error tracking - PHP SDK
统计信息
- 总下载量: 466
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-07-22