Quantcast
Channel: blog.atwork.at
Viewing all articles
Browse latest Browse all 1118

Get the daily Bing picture as background in your Teams meetings automatically

0
0

The Microsoft Bing Search Engine provides a professional and beautiful picture every day, you can see it online at www.bing.com. With the Bing API, you can easily get the images for your own use, e.g. to use them as custom background image in your Microsoft Teams calls. See how this works and download the ready-to-use PowerShell script here.

image

So, the task is to get the daily image information, to download the picture and to provide it as background picture in Teams.

Use custom images in Teams

To start at the end: You can use custom images by copying picture files in the local user´s folder %APPDATA%\Microsoft\Teams\Backgrounds\Uploads. Here, I have 3 images in that directory.

image

In the Teams client, in a call, the user can select the custom images with the "more actions" icon and in the "Show background effects". Then the panel Background settings opens and allows to select a custom image and to apply that as follows. Custom images are shown at the end of the images list. Here, we see the 3 images of the Upload folder.

image

We need to save the Bing picture in that folder. That folder %APPDATA%\Microsoft\Teams\Backgrounds\Uploads only exists if the current user has the Teams client installed on the computer.

Get the daily Bing image

Kindly, there exists a Bing service to get the information for the current Bing picture. I found some useful information in a Bash file in pedrosland/bing-rotate.sh gist repository and in an old codeproject article. You can get the Photo of the day information in several formats with an easy to use API anonymously. The photo data can be downloaded in XML, RSS and JSON formats with the following link. We can use the format parameter with the values xml, rss or js for JSON. Here, we use JSON.

HTTP GET: https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US

The idx parameter determines the day: 0 is the current day, 1 is the previous day, etc. This goes back for max. 7 days. If you use a larger number, you always get the 7 days old picture. The n parameter defines how many pictures you want to load. Usually, n equals 1 to get the latest picture (of today) only. Finally, mkt defines the culture you want to get, like en-US, de-DE, etc.

When executing this HTTP request in JSON format in a browser, you get back information about the daily Bing picture analogously as follows:

{
"images":[
{"startdate":"20200507",
"fullstartdate":"202005070700",
"enddate":"20200508",
"url":"/th?id=OHR.WildflowerWeek_EN-US0188713175_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp",

} ],
"tooltips": {…}
}

As we see, the images object returns an array. In this sample with n=1, and there´s only one picture included. You can run the HTTP request in the browser to see the current result quickly.

Use the PowerShell script GetDailyBingPicture.ps1

To automate that with PowerShell, we use The Invoke-WebRequest method in a script file GetDailyBingPicture.ps1. You can download the ready-to-use script from my GitHub repository GetDailyBingPicture.ps1here.

# GetDailyBingPicture.ps1 by @magrom
$uri = "https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US"
$response = Invoke-WebRequest -Method Get -Uri $uri

This does the first part of the job.

Analyze the data of the Bing image(s)

With the information above, we can parse that result to get the picture and to generate a nice filename. The $response contains a Content object (as we saw above) and we are interested in that data. The output of $response looks as here.

StatusCode        : 200
StatusDescription : OK
Content           : {"images":[{"startdate":"20200507","fullstartdate":"202005070700","enddate":"20200508","url":"/th?id=OHR.Wildflow
                     erWeek_EN-US0188713175_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp","urlbase":"/th?id...
RawContent        : HTTP/1.1 200 OK

Now we can work with that data.

Load the daily Bing image

As second part of the script, we convert the JSON data of Content to access the key and value pairs. Then, we access the first image data with the information we need, which is the URL to download the picture and the date and the title of the image to generate a friendly filename including the date. Finally, we load the image and save it to the Teams/Upload folder.

# Extract the image content
$body = ConvertFrom-Json -InputObject $response.Content
$fileurl = "https://www.bing.com/"+$body.images[0].url
$filename = $body.images[0].startdate + "-"+$body.images[0].title.Replace(" ","-").Replace("?","") + ".jpg"

# Download the picture to %APPDATA%\Microsoft\Teams\Backgrounds\Uploads
$filepath = $env:APPDATA + "\Microsoft\Teams\Backgrounds\Uploads\" + $filename
Invoke-WebRequest -Method Get -Uri $fileurl -OutFile $filepath

# Job done.

This does the job. The daily Bing picture is downloaded to the Teams/Upload folder with a nicely formatted and safe filename with the date and the picture title like 20200507-Where-the-wildflowers-grow.jpg. If the file already exists, it will be overwritten.

Download the script

Click here to get the PowerShell script from my GitHub repository.

image

Automate at user logon

To automate the daily downloading, open the Local Group Policy Editor (GPO) and navigate to User configuration - Windows Settings - Scripts (Logon/Logoff) . Double click the Logon item on the right. In the Logon Properties box, click on the PowerShell Scripts tab. Open Show Files. This opens the Explorer with the file path C:\WINDOWS\System32\GroupPolicy\User\Scripts\Logon. Copy the script GetDailyBingPicture.ps1 in that folder. Then, click Add… and add the file GetDailyBingPicture.ps1. Then click OK. The configuration should look as here.

image

Don´t forget to set the PowerShell settings "Allow local scripts and remote signed scripts" to RemoteSigned (run Set-ExecutionPolicy RemoteSigned), so that the script is allowed to run. See the article at Running PowerShell Startup (Logon) Scripts Using GPO for more details.

Check it

After the logon configuration in the GPO is done, logoff and login. Then, check the teams Upload folder %APPDATA%\Microsoft\Teams\Backgrounds\Uploads.

image

If everything worked, you should see the daily Bing picture in that folder as here: 20200507-Where-the-wildflowers-grow.jpg

Use it

Finally, open Teams. In a call, select the preferred Bing picture that´s automatically downloaded to your computer.

image

Summary

It´s easy to get the beautiful Bing pictures on your computer for your personal use with the PowerShell script and to use them in your Teams calls. Of course, it´s not recommended to have hundreds of pictures in your Teams/Upload folder. My recommendation would be to automatically download the daily Bing pictures to a local folder with the GetDailyBingPicture.ps1 script and manually copy your favorite pictures only to the Teams/Upload folder. Or, use the same file name and simply overwrite the daily picture every day automatically. Feel free to adapt the script and the process as needed. I hope this article helps with that task.

Enjoy!


Viewing all articles
Browse latest Browse all 1118

Latest Images

Trending Articles