Scaling and cropping an image adaptively based on the window dimensions
This seems like the kind of thing that should be done purely in CSS using media queries, specifically orientation.  When the window is taller than it is wide, the rules inside

@media all and (orientation: portrait) { … }


… would apply.  When the window is wider than it is tall, it would be

@media all and (orientation: landscape) { ... }


Furthermore, I would consider that image to be background-image styling for &lt;h2&gt;The post title&lt;/h2&gt; rather than an &lt;img&gt; element in its own right.  The scaling should be handled by a background-size rule.