Currently, I'm in the process of developing a small web application that uses the Spotify API to fetch and showcase top tracks and artists to users.
Each track or artist is presented within a Bootstrap panel, with the title displayed in the header and the corresponding image in the body.
While this method works effectively for tracks due to consistent image dimensions in the API response, it poses challenges for artists as their images have varying sizes.
My attempt to address this involved using one of the images from the array and setting the height and width to 100%, but this approach doesn't yield optimal results in all cases, especially when dealing with non-square images or low-resolution ones that get distorted by the styling.
The code snippet below showcases how the panels are structured:
<div class="col-md-4" v-if="type == 'artists'" v-for="track in tracks">
<div class="panel panel-default">
<div class="panel-heading">@{{ track.name }}</div>
<div class="panel-body"><img :src="track.images[0].url" :alt="track.name" class="img-responsive center-block" style="height: 100%; width: 100%"/></div>
</div>
</div>
Below are examples of what you might find in the image array:
"images":[
{
"height":640,
"url":"https://i.scdn.co/image/64758843803a4cbda8c0413cb06dc896d74a0964",
"width":640
},
...
]
"images":[
{
"height":666,
"url":"https://i.scdn.co/image/dd1ea0b4e68b25e2a82de61b03ee3933be266475",
"width":1000
},
...
]
I'm utilizing Vue.js to interact with the API and display content on my site.
If anyone has suggestions on how to consistently render images regardless of resolution variations, please share any CSS tricks or JavaScript solutions that could come in handy!