• Hello.
    I’m creating my own theme built on Bones by Eddie Machado.

    I’ve figured out how to create custom image sizes.

    I upload an image 1500 x 1200 to the media library.

    In functions.php I put the following code:

    add_theme_support( 'post-thumbnails' );
    
    add_image_size( 'nadge-big', 950, 760, true );
    // 950 x 760 is same aspect ratio as 1500 x 1200
    
    add_filter( 'image_size_names_choose', 'nadge_custom_image_sizes' );
    
    function nadge_custom_image_sizes( $sizes ) {
        return array_merge( $sizes, array(
            'nadge-big' => __('950px x 760px'),
        ) );
    }

    In a custom page template (which I’ve associated with a new page) I put the following inside the wordpress loop:

    <?php the_post_thumbnail('nadge-big'); ?>

    Then I view my page in a browser and inspect the image.
    All good. The image is exactly 950px x 760px.

    BUT when I then go to my page, insert cursor into the edit area, click ‘Add Media’, select my 1500 x 1200 image, then look at Size dropdown (under Attachment Display Settings) I see the following size option:

    950px x 760px – 680 x 544
    (950px x 760px is the name of the image size)
    Link to screenshot

    and when I click ‘Insert into page’ then update and view the page in a browser the image is indeed 680 x 544px.

    And 680 x 544 is the same aspect ratio as 950 x 760 and 1500 x 1200!

    It appears that WordPress is performing a further scaling of the image.

    I must be doing something wrong but I just don’t see it.

    Would appreciate it if someone could point me in the right direction.

  • The topic ‘Custom Image Sizes not working as expected’ is closed to new replies.