Try 30 days of free premium.

Get Background Image - Simple Example

TheSpoilerGirl wrote a year ago: 1

Hi.

Does anyone have a simple example of getting the first background image of a show in either PHP or JS. Just want to pass in a showid/number and to get a link to the first background image.

Thanks in advance


gazza911 wrote a year ago: 2

@TheSpoilerGirl wrote:
Hi.

Does anyone have a simple example of getting the first background image of a show in either PHP or JS. Just want to pass in a showid/number and to get a link to the first background image.

Thanks in advance

Something like this would output the first background URL:

var showid = 100;
$.get('https://api.tvmaze.com/shows/' + showid + '/images', function (data) {
   var backgrounds = data.filter(function(image) {
       return image.type === 'background';
   });
   console.log(backgrounds.length > 0 ? backgrounds[0].resolutions.original.url : 'No background images');        
});

TheSpoilerGirl wrote a year ago: 1

Thank you Gazza. That's brilliant just what I needed.

Thanks for taking the time to reply, much appreciated.

Try 30 days of free premium.