Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
1 <!DOCTYPE>
2 <head>
3 <style>
4 body {
5 border: 0px;
6 margin: 0px;
7 padding: 0px;
8 }
9 </style>
10 </head>
11 <body>
12 <img src="image-orientation-viewbox-no-size.svg">
14 <script>
15 var orientation = location.search.substring(1).split("&");
16 var angle = orientation[0];
17 var flip = orientation[1] == "flip" ? true : false;
19 // Construct a style. "from-image" is special-cased.
20 var orientationStyle;
21 if (angle == "from-image") {
22 orientationStyle = "image-orientation: from-image;";
23 } else {
24 orientationStyle = "image-orientation: "
25 + angle + "deg"
26 + (flip ? " flip" : "")
27 + ";";
28 }
30 // Since the SVG image has no intrinsic size, we need to apply an
31 // appropriate size to the <img> element to match the reference.
32 var boxStyle;
33 if (angle == "90" || angle == "270") {
34 boxStyle = "width: 200px; height: 100px;";
35 } else {
36 boxStyle = "width: 100px; height: 200px;";
37 }
39 var style = "img { "
40 + orientationStyle
41 + " "
42 + boxStyle
43 + " }\n";
45 // Apply the style to the document.
46 var sheet = document.createElement('style');
47 sheet.innerHTML = style;
48 document.body.appendChild(sheet);
49 </script>
50 </body>