grubersjoe/bing-daily-photo

一个用于获取 Bing 每日图片及其元数据的类

v4.1.0 2022-10-09 16:58 UTC

This package is auto-updated.

Last update: 2024-09-09 21:00:10 UTC


README

CI

BingPhoto 是一个简单的 PHP 类,用于获取 Bing 的每日图片及其元数据。

也可以在本地缓存图片,这对于与周期性 cronjob 结合使用非常有用。有关此(可选)功能的更多信息,请参阅 cacheDir 参数。免责声明:这可能会涉及版权问题。

安装

使用 Composer 安装此包

composer require grubersjoe/bing-daily-photo

基本用法

<?php
$bing = new BingPhoto();
$image = $bing->getImage();

// Example result ($image)
[
    [startdate] => '20160913'
    [fullstartdate] => '201609130700'
    [enddate] => '20160914'
    [url] => 'http://www.bing.com/az/hprichbg/rb/Meteora_EN-US6763889417_1920x1080.jpg'
    [urlbase] => '/az/hprichbg/rb/Meteora_EN-US6763889417'
    [copyright] => 'Roussanou and other monasteries in Metéora, Greece (© Stian Rekdal/Nimia)'   
    // ...
]

参数/选项

示例

// Fetches two images of the day starting yesterday from Bing
$bing = new BingPhoto([
    'n' => 2,
    'date' => BingPhoto::YESTERDAY
]);

foreach ($bing->getImages() as $image) {
    printf('<img src="%s">', $image['url']);
}
// Fetches the current image of the day in low resolution from the French Bing portal
$bing = new BingPhoto([
    'locale' => 'fr-FR',
    'quality' => BingPhoto::QUALITY_LOW,
]);

printf('<img src="%s">', $bing->getImage()['url']);
// Fetches three images of the day in high quality from the German Bing portal, starting yesterday
$bing = new BingPhoto([
    'n' => 3,
    'date' => BingPhoto::YESTERDAY,
    'locale' => 'de-DE',
    'quality'r => BingPhoto::QUALITY_HIGH,
]);

foreach ($bing->getImages() as $image) {
    printf('<img src="%s">', $image['url']);
}
// Fetches the current image of the day in portrait orientation
$bing = new BingPhoto([
    'orientation' => BingPhoto::ORIENTATION_PORTRAIT
]);
// Using the local cache 
$bing = new BingPhoto([
    'cacheDir' => '/tmp/bing-photo',
    'n' => 5,
    'quality' => BingPhoto::QUALITY_LOW,
]);