https://github.com/grubersjoe/bing-daily-photo
A simple PHP class to fetch Bing's photo of the day.
https://github.com/grubersjoe/bing-daily-photo
bing bing-image php
Last synced: 6 months ago
JSON representation
A simple PHP class to fetch Bing's photo of the day.
- Host: GitHub
- URL: https://github.com/grubersjoe/bing-daily-photo
- Owner: grubersjoe
- License: mit
- Created: 2014-04-21T16:47:19.000Z (over 11 years ago)
- Default Branch: main
- Last Pushed: 2022-10-09T17:04:15.000Z (about 3 years ago)
- Last Synced: 2025-03-29T02:11:55.275Z (7 months ago)
- Topics: bing, bing-image, php
- Language: PHP
- Homepage:
- Size: 118 KB
- Stars: 35
- Watchers: 5
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Bing Daily Photo

BingPhoto is a simple PHP class to fetch Bing's image of the day with meta data.
It is also possible to cache the images locally, which can be useful in combination with a periodic cronjob. See the `cacheDir` parameter for this (optional) feature. Disclaimer: this might be a copyright issue.
## Installation
Use [Composer](https://getcomposer.org/) to install this package:
```sh
composer require grubersjoe/bing-daily-photo
```## Basic usage
```php
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)'
// ...
]
```## Parameters / options
| Parameter | Description | Default | Valid values |
|---------------|------------------------------------------------------|------------------------------------|-------------------------------------------------------------------------------------------------------------|
| `cacheDir` | Directory for image caching | `null` | An existing directory, otherwise the directory will be created if possible |
| `date` | Date of photo | `BingPhoto::DATE_TODAY` | `BingPhoto::DATE_YESTERDAY`
`BingPhoto::DATE_TODAY`
`BingPhoto::DATE_TOMORROW`
`any integer >= -1` |
| `locale` | Locale code | `Locale::getDefault()` | Whatever language Bing supports |
| `n` | Number of photos to fetch, going from date backwards | 1 | 1 - 8 |
| `orientation` | Image orientation | `BingPhoto::ORIENTATION_LANDSCAPE` | `BingPhoto::ORIENTATION_LANDSCAPE`, `BingPhoto::ORIENTATION_PORTRAIT` |
| `quality` | Image resolution | `BingPhoto::QUALITY_HIGH` | `BingPhoto::QUALITY_LOW`
`BingPhoto::QUALITY_HIGH` |## Examples
```php
// Fetches two images of the day starting yesterday from Bing
$bing = new BingPhoto([
'n' => 2,
'date' => BingPhoto::YESTERDAY
]);foreach ($bing->getImages() as $image) {
printf('', $image['url']);
}
``````php
// 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('
', $bing->getImage()['url']);
``````php
// 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('', $image['url']);
}
``````php
// Fetches the current image of the day in portrait orientation
$bing = new BingPhoto([
'orientation' => BingPhoto::ORIENTATION_PORTRAIT
]);
``````php
// Using the local cache
$bing = new BingPhoto([
'cacheDir' => '/tmp/bing-photo',
'n' => 5,
'quality' => BingPhoto::QUALITY_LOW,
]);
```