This is not possible with JavaScript and it’s not JS that is doing that in the examples you posted, either. These are different images, indeed, and if they haven’t been created with a photo editor in advance, they are at least being created/manipulated dynamically with a server side script (which the image URLs also suggest if you view the single images in the browser).
For example, the URL of the images at polywoodinc.com look like this:
- http://www.polywoodinc.com/media/catalog/product/cache/1/image/400x/9df78eab33525d08d6e5fb8d27136e95/A/D/AD5030WH_1.jpg
- http://www.polywoodinc.com/media/catalog/product/cache/1/image/400x/9df78eab33525d08d6e5fb8d27136e95/A/D/AD5030GR.jpg
- http://www.polywoodinc.com/media/catalog/product/cache/1/image/400x/9df78eab33525d08d6e5fb8d27136e95/A/D/AD5030MA.jpg
It’s even more obvious on the other site:
- http://www.case-mate.com/getDynamicImage.aspx?path=Blacktank1.jpg&w=480&h=480&q=100
- http://www.case-mate.com/getDynamicImage.aspx?path=iph4s-TANK-navyAUQA2.jpg&w=480&h=480&q=100
- http://www.case-mate.com/getDynamicImage.aspx?path=getDynamicImage-4.jpg&w=480&h=480&q=100
These URL query strings show that they actually seem to be multiple separate images that have been created beforehand, and the script is resizing them dynamically. But with an image manipulation library like
GD or
ImageMagick you might be able to manipulate blank canvas images on the fly, too.