Is it possible to get the URL, height and width of an image where the height and width are as a minimum the size I specify?
wp_get_attachment_image_src() almost does this, but not quite, grabbing instead the image where either one of the height or width is as a minimum the size I specify.
For example this ->
wp_get_attachment_image_src(get_the_ID(), array(208,208)); will return these results -
array ( 0 => 'http://localhost/wp-content/uploads/2014/04/image-name-300x168.jpg', 1 => 208, 2 => 116, 3 => true, )
As you can see, the height is less than 208, so when I display the image using those attributes it becomes stretched.
so in the case of the above I would actually require WP to find the next size image and return these results -
array ( 0 => 'http://localhost/wp-content/uploads/2014/04/image-name-672x372.jpg', 1 => 376, 2 => 208, 3 => true, )
Naturally I don't just want to grab the original (thus largest) image as that will unnecessarily eat bandwidth and cause the page load to be slower.
In case you are wondering why I require this, I am displaying 4x images in a row in a square container (208x208). The images are both horizontally and vertically centered, and I need the images to fill the container while being as small as possible.
<?php if($this->items->have_posts()) : while($this->items->have_posts()) : $this->items->the_post(); $last = ($this->is_last_on_line()) ? 'last' : false; $media_preview = wp_get_attachment_image_src(get_the_ID(), array(208,208)); $sizing = ($media_preview >= $media_preview) ? 'height="208"' : 'width="208"'; ?> <div id="post-<?php the_ID(); ?>" class="preview-container <?php echo $last; ?>"> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"> <img src="<?php echo $media_preview; ?>" <?php echo $sizing; ?> /> </a> </div> <?php endwhile; endif; wp_reset_query();