定制 joukhar/laravel-pixabay 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

joukhar/laravel-pixabay

最新稳定版本:v1.1.0

Composer 安装命令:

composer require joukhar/laravel-pixabay

包简介

Laravel package for accessing the Pixabay API effortlessly.

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Overview

LaravelPixabay is a Laravel package that simplifies the process of interacting with the Pixabay API. It provides a way to search and retrieve images and videos from the Pixabay platform with minimal effort. This package includes various customizable options like image/video type, categories, order, page results, and more.

Requirements

Support us

If you find my packages useful, consider buying me a coffee to support further development.

Buy Me A Coffee

Installation

You can install the package via composer:

composer require joukhar/laravel-pixabay

You can publish the config file or add pixabay service to (config/services.php) file:

php artisan vendor:publish --tag="laravel-pixabay-config"

Configuration file (config/pixabay.php):

return [
    'key' => env('PIXABAY_API_KEY'),
];

Then add your Pixabay API key to the .env file:

PIXABAY_KEY=your_pixabay_api_key

Usage

get images

$laravelPixabay = new Joukhar\LaravelPixabay();
$laravelPixabay->getImages();

get specific image

$laravelPixabay = new Joukhar\LaravelPixabay();
$laravelPixabay->getImages(id:"< IMAGE ID HERE >");

get images with specific type ( Default : PixabayImageType::ALL )

use Joukhar\LaravelPixabay\Enums\PixabayImageType;

$laravelPixabay = new Joukhar\LaravelPixabay();
$laravelPixabay->getImages(type: PixabayImageType::ILLUSTRATION );

get videos

$laravelPixabay = new Joukhar\LaravelPixabay();
$laravelPixabay->getVideos();

get videos with specific type ( Default : PixabayVideoType::ALL )

use Joukhar\LaravelPixabay\Enums\PixabayVideoType;

$laravelPixabay = new Joukhar\LaravelPixabay();
$laravelPixabay->getVideos(type: PixabayVideoType::ANIMATION);

get specific video

$laravelPixabay = new Joukhar\LaravelPixabay();
$laravelPixabay->getVideos(id:"< VIDEO ID HERE >");

Customizing API Requests

You can customize your queries using several configuration methods provided by the LaravelPixabay class.

Set Current Page

You can specify which page of results to fetch using setCurrentPage():

$pixabay->setCurrentPage(2);

Set Maximum Results Per Page

The number of results per page can be adjusted using setMaxResults():

$pixabay->setMaxResults(50);

Enable Safe Search

To filter out adult content, use setSafeSearch():

$pixabay->setSafeSearch(true);

Only Editor's Choice

You can request only editor's choice images or videos using setOnlyEditorChoice():

$pixabay->setOnlyEditorChoice(true);

Set Category

To fetch resources of a specific category, use setCategory():

use Joukhar\LaravelPixabay\Enums\PixabayCategory;

$pixabay->setCategory(PixabayCategory::NATURE);

Set Order

To order results by popularity, latest, or custom order, use setOrder():

$pixabay->setOrder('latest');

Set Minimum Dimensions

You can set the minimum width and height for the images/videos to be returned using setDimentions():

$pixabay->setDimentions(800, 600);

Example: Fetching Nature Photos

use Joukhar\LaravelPixabay\LaravelPixabay;
use Joukhar\LaravelPixabay\Enums\PixabayCategory;
use Joukhar\LaravelPixabay\Enums\PixabayImageType;

$pixabay = new LaravelPixabay();
$photos = $pixabay
    ->setCategory(PixabayCategory::NATURE)
    ->setMaxResults(10)
    ->setSafeSearch(true)
    ->getImages(null, PixabayImageType::PHOTO);

Exception Handling

If there is an issue with the API request (e.g., invalid API key, request failure), the package throws an Exception with a detailed error message.

try {
    $images = $pixabay->getImages();
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 16
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 664
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-21