Is it possible to show total number of pixels, size in MP, aspect ratio of current featured image?
For example I use this to echo image dimensions of full sized featured image of current post.
if ( has_post_thumbnail()) {
$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
// echo image width
echo $thumb_image_url[1];
// echo image height
echo $thumb_image_url[2];
And I get for example dimensions: 2048 x 1536.
Is it possible to make separate functions to calculate:
- Total number of pixels width x height? (example 2048 x 1536 = 3.145.728 pixels)
- Transform total number of pixels in megapixels? (3.14 megapixel)
- Function to calculate aspect ratio based on image width and height? (1,33:1 - 4:3 (screen))
More info about megapixel and aspect ratio calculator on: http://web.forret.com/tools/megapixel.asp
I would go little further also. I think it is possible to get aspect ratio as: standard (lansdcape), portrait or square (approximately).
Standard (most used) image aspect ratio width / height is 4:3, landscape, which is mathematically also 1:1.3333333333333 (example 1600 x 1200 pixels photo).
Portrait would be 0.75 (example 1600 x 1200 pixels photo).
And square would be 1:1 ((example 1200 x 1200 pixels photo).
What I think would be great is to make function which will check result of aspect ratio.
If it is 1.33 (or even better if it is more than 1.2 in case image is little cropped) than to return "Landscape image".
If it is 0.75 (or even better if it is less than 0.8 in case image is little cropped) than to return "Portrait image".
If it is more that 0.8 but less than 1.2 than to return "Square like".
Any suggestions?