Change Blogger YouTube Thumbnail Size

I just started playing with Blogger with my new blog. There's usually a lot of learning when experimenting with new technology or products. I thought it would be a good idea to share the learning & experience with the world. I picked the Galauness template designed by  iksandi after an hour of googling which is a nice minimalist template to get started with. The best thing I like about the template is it's simplicity. As you can see it has a nice & simple grid layout with sliding thumbs (achieved with few lines of Jquery) in the home page. It also displays the YouTube thumbnails if there's YouTube video embedded in the post. A quick look at the template code shows that the following function does the job:

<script>
function snips_image_creator(image_url,post_title)
{
var image_size=400;
var show_default_thumbnail=true;
var default_thumbnail="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLBh-YrV_6tM59GNAYtFBW0s5v8ATBSIUIypvYaVhAimchEebmzPCdZLfchbrWGLj5MdggtsA_4Zt7ATii3eHPcR0NbZggX1bIMf0W36SSQgFI6LSO-DItemzTHZGlHtDi9u6aKVB7dCQ/s72-c/default.png";
if(show_default_thumbnail == true && image_url == "") image_url= default_thumbnail;
image_tag='<img alt="'+post_title+'" src="'+image_url.replace('/s72-c/','/w'+image_size+'/')+'" />';
if(image_url!="") return image_tag; else return "";
}
</script>

and the following code finally prints the output to the page:
<script>
document.write(
snips_image_creator("<data:post.thumbnailurl=".thumbnailurl">","<data:post.title=".title">")
);
</script>
As you might have already noticed it gets the post thumbnail URL by calling "data:post.thumbnailUrl" which is a layout data tag. More about available layout data tags look here. I'm not sure why post.thumbnailUrl is not documented though. Anyways, so in case of regular post images (uploaded to blogge/picasa) the URL would be something like this:

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLBh-YrV_6tM59GNAYtFBW0s5v8ATBSIUIypvYaVhAimchEebmzPCdZLfchbrWGLj5MdggtsA_4Zt7ATii3eHPcR0NbZggX1bIMf0W36SSQgFI6LSO-DItemzTHZGlHtDi9u6aKVB7dCQ/w72/default.png

Notice the "w72" ,this value can be used to change the size of the image (and a lot more). More details about it here. So, that's how it works for regular post images. However, for YouTube thumbnails blogger returns the default thumbnail of the video. For example:

http://img.youtube.com/vi/wKJ9KzGQq0w/default.jpg


It's good enough for a thumbnail, but for the template I'm using I needed a bit larger image. Of-course, I can set manual width/height to the image but that's look ugly as the original size of the image is 120x90. The good part is YouTube provides another size 480x360 for the image (Check this post out for all supported thumbnail parameters YouTube). We just need to change the file name of the image from "default" to "0". For example:

http://img.youtube.com/vi/wKJ9KzGQq0w/0.jpg

Cool, so that's the size I needed. Next, I simply modified the snips_image_creator function a little bit. Here's what I did:
<script>
function snips(image_url, post_title) {
 var image_size = 600;
 var show_default_thumbnail = true;
 var default_thumbnail = "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLBh-YrV_6tM59GNAYtFBW0s5v8ATBSIUIypvYaVhAimchEebmzPCdZLfchbrWGLj5MdggtsA_4Zt7ATii3eHPcR0NbZggX1bIMf0W36SSQgFI6LSO-DItemzTHZGlHtDi9u6aKVB7dCQ/s72-c/default.png";
 if (show_default_thumbnail == true && image_url == "")
  image_url = default_thumbnail;
 image_tag = '<img src="' + image_url.replace('/s72-c/', '/w' + image_size + '/') + '" alt="' + post_title + '"/>';
 yimage_tag = '<img src="' + image_url.replace('default', '0') + '" alt="' + post_title + '"/>';
 if (image_url.indexOf("img.youtube.com")!= -1){
  return yimage_tag;
 }
 else if (image_url != "")
 {
 return image_tag;
 }
 else
 return "";}
</script>

So, basically it I added few lines of code to detect YouTube URL, find the keyword "default" in the URL and replace it with "0". That's it !



11 comments:

  1. Hey! Thank you very much for this tutorial, it helped me a lot!
    I've sent you a message on Facebook, regarding a similar issue.. I hope you can help me..

    Thank You!

    ReplyDelete
    Replies
    1. Glad it helped you buddy. I'm not active on FB but will check it out.

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Hey Dave, do you still have the problem man? Your home page looks cool to me ! No broken links.

    ReplyDelete
  4. not working..
    i copied the code and put in the right place.
    after inserting the code i got the following notice:

    -------------------------------------------------
    Error parsing XML, line 1741, column 38: The entity name must immediately follow the '&' in the entity reference.
    -------------------------------------------------

    So, i put " && " instead of " && " in the following line. then it gets accepted by the blogger xml .
    ------------------
    if (show_default_thumbnail == true && image_url == "") image_url = default_thumbnail;
    ----------------------



    I created a post by the embed code from youtube:
    -----------------------------------

    ------------------------------------

    I refreshed the home page with that video post on it, to see changes.

    there was no thumbnail. There was this big video player from youtube.

    Help me please !!!!
    my site www.funmist.com

    ReplyDelete
  5. Hi, Not sure if you could help me out here I am trying to apply the the same template on my blog but I could get the thumbnail to load. (Not even at the main page). Not sure if I miss anything here. Most of my images are hosted in smugmug (which is not from picassa - Not sure if that the problem, but any inputs from you definitely will help for my case here)

    And also for the item page, I would like to remove the left nav bar and which left only the middle column. Not sure if you could teach me on how to do so.

    Thanks and appreciate all the help and input you give here. Hope to hear from you soon.

    My blog URL is as below:
    http://chbetasite.blogspot.com/

    ReplyDelete
  6. Hi Grepable. Thanks for the advice. I'm struggling too to get video to work on the homepage without using the embed fuction. But then the image on my blog's homepage doesn't fade like images do. Any advice would be welcome: http://sajumuthalaly.blogspot.co.uk/

    ReplyDelete
  7. Hello Grepable! I know you haven't posted here in a long while so I really hope you see this. i've been googling all day searching for a way to make some changes to my galauness home page (since the designer never responds). And you're the only person I've run across who may be able to give me advice, it seems you really know your stuff!
    I've been using galaunesss for a long time (someone else installed and customized it for me - sadly she's fallen off the face of the earth) I love the layout for the posts but I really don't love the homepage thumbnails as much anymore. Do you know if there might be a way to change it so that my home looks like any other page with my sidebar in it? I'd rather it just be a list of post previews with a simple "read more" for each instead of the sliding thumbnail grid .. obviously I am completely tech illiterate when it comes to html and whatnot. Is this even possible???

    ReplyDelete
  8. Hello Grepable! I know you haven't posted here in a long while so I really hope you see this. i've been googling all day searching for a way to make some changes to my galauness home page (since the designer never responds). And you're the only person I've run across who may be able to give me advice, it seems you really know your stuff!
    I've been using galaunesss for a long time (someone else installed and customized it for me - sadly she's fallen off the face of the earth) I love the layout for the posts but I really don't love the homepage thumbnails as much anymore. Do you know if there might be a way to change it so that my home looks like any other page with my sidebar in it? I'd rather it just be a list of post previews with a simple "read more" for each instead of the sliding thumbnail grid .. obviously I am completely tech illiterate when it comes to html and whatnot. Is this even possible???

    ReplyDelete
  9. Hi,

    I can't seem to figure out how to use the drop down menu and about me tab? How do I link to them?

    ReplyDelete
  10. Hi,
    Where do I put these codes in my Blogger template to resize the data:thumbnail? Thanks.

    ReplyDelete