Tuesday, 26 February 2013

Random blog banner - Part 1

You probably have noticed: the banner image of this blog changes every time you refresh the page. Those are stitched panorama from many pictures, sometimes spanning a full 360 degrees, sometimes less (I will write something about stitching these panoramas at some point...).

The code to do randomize the banner image is easily available online, I took it from this page, but it is found in so many places that I'm not sure who wrote it first.

Let's take it step by step. I define 3 arrays: banner, shift, and information, each index representing one image:

banner contains the URL of the image. I extract the public link from the Picasa Web Albums. This URL can be obtained by a right-click on the image, and then "View Image". The URL looks like this: https://lh6.googleusercontent.com/.../s1600/X.jpg. The number after the letter s is particularly interesting: it defines the width of the image. I you change it, Google will very nicely resize it to the size you want. Using s0 gives you the original resolution.

shift contains some extra CSS style information. For full 360° panoramas, the image can be repeated endlessly without seems, so the parameter repeat is used, otherwise, the panorama is shown only once. Also, you can set an offset, so that the image gets centered vertically, so you don't get only sky or only land/sea in the banner.

Finally, the code generates a little piece of CSS style, that will set the banner image. Also, it modifies the HTML element with id headerinformation, so that it shows the image information. In my case, this element is at the bottom of the banner, aligned to the right, and tells you where the image was taken.

All right. All for now, next post will show how to generate the script, as well as this page, automatically.