Using PHP function getimagesize()
you can get width
and height
of your image:
list($width, $height) = getimagesize($imageUrl);
Then, in your template:
<?php if($width > $height): ?>
//put css here as you want
<?php else: ?>
//put css here as you want
<?php endif; ?>