My solution was a more intricate transformation
and using a table instead of divs to handle the photos. The reason I wanted to get image dimensions was to declare the size of the containing div on the fly. The images vary depending on the subject, some are narrow, some wide, but I wanted to have only one template for news articles, not one for each photo possibility.
While tables are old-school, this was once instance where they offer better presentation in terms of setting auto margins than divs.
Here is the transformation for handling the photos if there are any attached to the article. If there are no photos, the area collapses and the spacing between the headline and body appear normally. I also have a javascript running on the page that displays the a large version of the photo and caption in a pop-up. (There are no cr-lf's in the actual transformation because they can create spaces in the html.)
<table id="containphoto"><tbody><tr>
<td class="newsphoto">
<%# IfEmpty(Eval("File01"), "", "<a rel=\"thumbnail\" title=\"" + Eval("Caption01") + "\" href=\"" + GetFileUrl("File01") + "\"><img src=\"" + GetFileUrl("File01") + "?maxsidesize=300\" /></a>") %>
<%# (Eval("Credit01").ToString() == "" ? "" : "<div class='newsphotocredit'>Photo by " + Eval("Credit01") + "</div>") %></div></td>
<td class="newsphoto"><%# IfEmpty(Eval("File02"), "", "<a rel=\"thumbnail\" title=\"" + Eval("Caption02") + "\" href=\"" + GetFileUrl("File02") + "\"><img src=\"" + GetFileUrl("File02") + "?maxsidesize=300\" /></a>") %>
<%# (Eval("Credit02").ToString() == "" ? "" : "<div class='newsphotocredit'>Photo by " + Eval("Credit02") + "</div>") %></div></td>
<td id="newsphotocaption"><%# IfEmpty(Eval("Caption01"), "", "<p>" + Eval("Caption01") + "</p>") %><%# IfEmpty(Eval("Caption02"), "", "<p>" + Eval("Caption02") + "</p>") %></td>
</tr></tbody></table>
<%# (Eval("Caption01").ToString() == "" ? "" : "<div id=\"spacer\"> </div>") %>
Here's the CSS. The key feature for the template to not add any space when there's no photo is setting the padding to zero --
table#containphoto {
margin:0 auto;
padding:0;
border-collapse:collapse;
border-spacing:0 0;
}
td.newsphoto {
border-top:1px dotted rgb(210,210,210);
border-bottom:1px dotted rgb(210,210,210);
background-color:rgb(232, 237, 245);
empty-cells:hide;
padding:0;
}
td#newsphotocaption {
border-top:1px dotted rgb(210,210,210);
border-bottom:1px dotted rgb(210,210,210);
background-color:rgb(232, 237, 245);
empty-cells:hide;
padding:0;
}
.newsphoto {
vertical-align:middle;
}
.newsphoto img {
padding:0;
margin:6px 10px 4px 10px;
}
.newsphotocredit {
color:rgb(110,110,110);
font-size:9px;
text-align:right;
margin:0 10px 7px 0;
}
#newsphotocaption {
color:rgb(110,110,110);
font-size:11px;
text-align:justify;
vertical-align:middle;
}
#newsphotocaption p:first-line {
font-weight:bold;
}
#newsphotocaption p {
margin:10px 13px 10px 0;
}
Hope this helps anyone who wants to use a single template for uniformly handling photos of varying widths.
-Paul Zelewsky
New Media Editor
Law Bulletin Publishing Co.
Chicago, Illinois USA