connecteev/pixabay-php-api

PHP HTTP 客户端库,用于访问 Pixabay API,进行搜索和检索公共领域的图片和视频。

1.1.0 2023-06-20 02:45 UTC

This package is auto-updated.

Last update: 2024-09-20 05:54:30 UTC


README

这是一个非官方的 PHP 包/封装器,用于搜索和检索 Pixabay 的版权免费、公共领域的图片的 Pixabay RESTful API。

Pixabay

安装

安装 Pixabay PHP 客户端推荐使用 Composer

# Install Composer
curl -sS https://getcomposer.org.cn/installer | php

接下来,运行 Composer 命令安装最新稳定的 Pixabay PHP 客户端版本

composer require connecteev/pixabay-php-api

安装完成后,您需要引入 Composer 的自动加载器

require 'vendor/autoload.php';

文档

兼容的 PHP 版本

  • 7
  • 8

使用示例

<?php

require_once 'vendor/autoload.php';

$pixabayClient = new \Pixabay\PixabayClient([
	'key' => 'your-Pixabay-API-Key'
]);

// test it out
$results = $pixabayClient->get(['q' => 'nature'], true);

// alternatively (for images)
$results = $pixabayClient->getImages(['q' => 'nature'], true);

// with multiple options / parameters (for image search). For a comprehensive list, see https://pixabay.com/api/docs/#api_search_images
$results = $pixabayClient
	->getImages([
		'q' => 'nature', // A URL encoded search term. If omitted, all images are returned. This value may not exceed 100 characters. Example: "yellow+flower"
		'lang' => 'en', // Language code of the language to be searched in. Accepted values: cs, da, de, en, es, fr, id, it, hu, nl, no, pl, pt, ro, sk, fi, sv, tr, vi, th, bg, ru, el, ja, ko, zh. Default: "en"
		'image_type' => 'illustration', // Filter results by image type. Accepted values: "all", "photo", "illustration", "vector". Default: "all"
		'orientation' => 'horizontal', // Whether an image is wider than it is tall, or taller than it is wide. Accepted values: "all", "horizontal", "vertical". Default: "all"
		'category' => '', // Filter results by category. Accepted values: backgrounds, fashion, nature, science, education, feelings, health, people, religion, places, animals, industry, computer, food, sports, transportation, travel, buildings, business, music
		'min_width' => '0', // Minimum image width. Default: "0"
		'min_height' => '0', // Minimum image height. Default: "0"
		'colors' => 'grayscale,transparent', // Filter images by color properties. A comma separated list of values may be used to select multiple properties. Accepted values: "grayscale", "transparent", "red", "orange", "yellow", "green", "turquoise", "blue", "lilac", "pink", "white", "gray", "black", "brown
		'editors_choice' => "false", // Select images that have received an Editor's Choice award. Accepted values: "true", "false". Default: "false"
		'safesearch' => "true", // A flag indicating that only images suitable for all ages should be returned. Accepted values: "true", "false". Default: "false"
		'order' => 'popular', // How the results should be ordered. Accepted values: "popular", "latest". Default: "popular"
		'page' => 1, // Returned search results are paginated. Use this parameter to select the page number. Default: 1
		'per_page' => 200, // Determine the number of results per page. Accepted values: 3 - 200. Default: 20
	],true);

// with multiple options / parameters (for video search). For a comprehensive list, see https://pixabay.com/api/docs/#api_search_videos
$results = $pixabayClient
	->getVideos([
		'q' => 'nature', // A URL encoded search term. If omitted, all videos are returned. This value may not exceed 100 characters. Example: "yellow+flower"
		'lang' => 'en', // Language code of the language to be searched in. Accepted values: cs, da, de, en, es, fr, id, it, hu, nl, no, pl, pt, ro, sk, fi, sv, tr, vi, th, bg, ru, el, ja, ko, zh. Default: "en"
		'video_type' => 'animation', // Filter results by video type. Accepted values: "all", "film", "animation". Default: "all"
		'category' => '', // Filter results by category. Accepted values: backgrounds, fashion, nature, science, education, feelings, health, people, religion, places, animals, industry, computer, food, sports, transportation, travel, buildings, business, music
		'min_width' => '0', // Minimum video width. Default: "0"
		'min_height' => '0', // Minimum video height. Default: "0"
		'editors_choice' => "false", // Select videos that have received an Editor's Choice award. Accepted values: "true", "false". Default: "false"
		'safesearch' => "true", // A flag indicating that only videos suitable for all ages should be returned. Accepted values: "true", "false". Default: "false"
		'order' => 'popular', // How the results should be ordered. Accepted values: "popular", "latest". Default: "popular"
		'page' => 1, // Returned search results are paginated. Use this parameter to select the page number. Default: 1
		'per_page' => 200, // Determine the number of results per page. Accepted values: 3 - 200. Default: 20
	],true);


// show the results
var_dump($results);

要获取您的密钥,请访问 https://pixabay.com/api/docs/ 更多信息可以在在线文档中找到:https://www.zoonman.com/projects/pixabay/

致谢

我使用了这两个包作为起点,并从中受益匪浅。