sage icon indicating copy to clipboard operation
sage copied to clipboard

Getting width of large thumbnail always displays 940 px

Open hixen opened this issue 13 years ago • 3 comments

Sorry if this has been flagged before.

Trying to show the width of of my uploaded media.

First i get all data for all sizes using this.

$thumb_full = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' ); $thumb_large = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large' ); $thumb_medium = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'medium' ); $thumb_small = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail' );

then I echo it out using this:

When echoing out the width of the large image, it always shows 940px, even if it's larger. (in my example 1024)

hixen avatar Jun 25 '13 07:06 hixen

This isn't a bug. You just need to set the content width to the size that suits your theme. You can even account for the sidebar as follows (the example uses Bootstrap's span8: span12 defaults);

if (!isset($content_width)) { $content_width = (roots_display_sidebar()) ? 770: 940; }

Foxaii avatar Jun 25 '13 07:06 Foxaii

Ok, if it isn't a bug, but I'm having a hard time to understand why I can output the correct width of my small, medium and full image width, but no the large image attachment.

I uploaded a image attachment in full size of 1920 x 2560 pixels, and in Settings > Media I have the following settings.

Thumbnail = 200 x 200 Medium = 600 x 1200 Large = 1800 x 3600

On my post I display the image with 4 links, one to each size (thumbnail, medium, large, full)

And I get the following results:

Thumbnail = 150 x 200 (image-150x200.jpg) Medium = 600 x 800 (image-600x800.jpg) Large = 940 x 1253 (image-1800x2400.jpg) Full = 1920 x 2560 (image.jpg)

I think i understand the concept of the $content_width, but I don't understand why the array of wp_get_attachment_image_src( $attachment_id, $size, $icon ); says one width, but the actual image is bigger.

But if this is not a bug I can simply add another size, i just skip the large version of the image attachment.

hixen avatar Jun 25 '13 19:06 hixen

The full size call ignores $content_width. Of your other sizes only the large is big enough to be affected by it.

Images will scale proportionally by default and this is probably preventing the right sizes being displayed. It can be overwritten in a checkbox under the size settings in media but you'll need to rebuild the thumbnails afterwards. There are plenty of plugins to do this, but it's all WordPress related, not Roots.

Foxaii avatar Jun 25 '13 21:06 Foxaii