Get Different Sizes of SlideShare thumbnails

Recently we were working on a feature we can show a slideshare gallery, we faced a little problem while we were trying to get thumbnails for slides.
We used Slideshare oEmbed API to get slide info and thumbnails. The API response was giving a small thumbnail which is 170x128 px.
But we needed large thumbnails. But in the documentation there are no option to get large thumnails. So we did a little research and find a little different solution to get large thumbnails(actually 4 types of thumbnail).

How to Get SlideShare Images:

Let's see the some code in action, how we solved the issue,

//the url with Oembed API info
$url = 'https://www.slideshare.net/api/oembed/2?url=https://www.slideshare.net/haraldf/business-quotes-for-2011&format=json';

//the response using file_get_content
$apiResponse = file_get_contents($url);
// JSON output to get thumnail result
$jsonData = json_decode($apiResponse, true);

If we var_dump the $jsonData, then we will get output like this.

{
 "type":"rich",
 "thumbnail_width":170,
 "version":"1.0",
 "thumbnail":"//cdn.slidesharecdn.com/ss_thumbnails/110103quotes2010-12-110103073149-phpapp01-thumbnail.jpg?cb=1294104671",
 "author_url":"https://www.slideshare.net/haraldf",
 "slide_image_baseurl":"//image.slidesharecdn.com/110103quotes2010-12-110103073149-phpapp01/95/slide-",
 "slideshow_id":6435157,
 "version_no":"1294104671",
 "provider_name":"SlideShare",
 "author_name":"Harald Felgner (PhD)",
 "provider_url":"https://www.slideshare.net",
 "thumbnail_height":128,
 "total_slides":75,
 "width":425,
 "height":355,
 "title":"Business Quotes for 2011",
 "slide_image_baseurl_suffix":"-1024.jpg"
 "conversion_version":2,
 "html":"\u003Ciframe src=\"https://www.slideshare.net/slideshow/embed_code/key/6PCWPGFw9SwsAY\" width=\"427\" height=\"356\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" style=\"border:1px solid #CCC; border-width:1px; margin-bottom:5px; max-width: 100%;\" allowfullscreen\u003E \u003C/iframe\u003E \u003Cdiv style=\"margin-bottom:5px\"\u003E \u003Cstrong\u003E \u003Ca href=\"https://www.slideshare.net/haraldf/business-quotes-for-2011\" title=\"Business Quotes for 2011\" target=\"_blank\"\u003EBusiness Quotes for 2011\u003C/a\u003E \u003C/strong\u003E from \u003Cstrong\u003E\u003Ca href=\"https://www.slideshare.net/haraldf\" target=\"_blank\"\u003EHarald Felgner (PhD)\u003C/a\u003E\u003C/strong\u003E \u003C/div\u003E\n\n"
}

Now we can use the thumbnail using $jsonData['thumbnail']. This will give a low resolution image.

Different Types of Image:

Now to get different types of images, we used the following code,

To get thumbnail with default resolution(provided by slideshare API), we can just use $jsonData['thumbnail']. So the url will be like this,
https://cdn.slidesharecdn.com/ss_thumbnails/110103quotes2010-12-110103073149-phpapp01-thumbnail.jpg?cb=1294104671

To get thumbnail with small size(120x90px), we have to change the url like this

$jsonData['thumbnail'] = str_replace("thumbnail.jpg", "thumbnail-2.jpg", $jsonData['thumbnail']);

This will create the image url like this,
https://cdn.slidesharecdn.com/ss_thumbnails/110103quotes2010-12-110103073149-phpapp01-thumbnail-2.jpg?cb=1294104671

To get thumbnail with Medium size(320x240px), we have to change the url like this

$jsonData['thumbnail'] = str_replace("thumbnail.jpg", "thumbnail-3.jpg", $jsonData['thumbnail']);

This will create the image url like this,
https://cdn.slidesharecdn.com/ss_thumbnails/110103quotes2010-12-110103073149-phpapp01-thumbnail-3.jpg?cb=1294104671

And for Large thumbnail(512x384px), we need to change the url like this

$jsonData['thumbnail'] = str_replace("thumbnail.jpg", "thumbnail-4.jpg", $jsonData['thumbnail']);

This will create the image url like this,
https://cdn.slidesharecdn.com/ss_thumbnails/110103quotes2010-12-110103073149-phpapp01-thumbnail-4.jpg?cb=1294104671

Now, by changing thumbnail name like this we can get these size of thumbnails for any slideshare slide.

comments powered by Disqus