• Hello.

    Several times over time I changed sizes of thumbnails WP generate when images are uploaded, always setting bigger size.

    Recently I set Thumbnail Width 600px width and Medium size Max Width 1800px.
    After several hundred images uploaded I realized that I need to set smaller image sizes, I reduced Medium size from 1800px to 1500px for future uploads.

    I know that already uploaded images will stay on disk in bigger resolution, and that is fine by me, I do not need to use any plugin to regenerate thumbs again.

    Problem:

    Word Press now shows that size for images uploaded before is also 1500px width, even real size is 1800px (for an example it shows 1500px x 1000px for image that is 1800px x 1200px).

    I changed few times width of future images in Dashboard > Settings > Media and I figured out that if real dimensions of already uploaded images are bigger than what is now set in Media Settings, WP will say that width of those images is the width that is set in Media Settings, even real dimensions are bigger.

    You can see screenshot example here: https://postimg.cc/fScS3WKH

    This is code I use to get image and its dimensions.

    $medium_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'medium'); // Featured image medium size
    
    // To show image dimensions   
    echo $medium_image_url[1]; // Show width
    echo $medium_image_url[2]; // Show height

    Is there any way to get real image dimension of already uploaded images which dimensions are bigger than one now set in media settings?

Viewing 1 replies (of 1 total)
  • WP shows wrong image dimensions

    I don’t think so.

    The developer documentation for wp_get_attachment_image_src(); clearly states that the $size parameter “Accepts any registered image size name, or an array of width and height values in pixels (in that order)”.

    So so when you pass a size name of “medium”, you’re telling WordPress to use the “registered size” for “medium”, which is exactly what you’re getting. But it looks like you’re expecting the function to query the previously-generated thumbnail image and return the actual size, which it doesn’t.

    This shouldn’t be a plugin if you would run a plugin one-time to re-generate your thumbnail images. Alternatively, you could pass the size “full” (instead of “medium”) to get the original image size (not the generated thumbnail).

Viewing 1 replies (of 1 total)

The topic ‘WP shows wrong image dimensions’ is closed to new replies.