• Resolved hyacinthus

    (@hyacinthus)


    When I upload a pic, and I look in the upload folder I find there are about 7 different size pics produced. I should be able to programatically choose which of those 7 I want to show, but I’m having difficulty figuring out how. I keep getting a thumbnail with the wrong size even though I’ve tried changing the thumbnail size in Media settings and then using Regenerate Thumbnails Advanced. How are the pics in the upload folder named or id’d? How can I select the one I want? Can I specify which is THE thumbnail?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator bcworkz

    (@bcworkz)

    A few default sizes are defined in WP core, the rest are defined by themes or plugins. add_image_size() is what is used.

    When the featured image is to be displayed, the template calls the_post_thumbnail(). The default image size is ‘post-thumbnail’, but you can specify as a parameter any valid image size as defined by add_image_size(). If you know the image dimensions you can alternately supply these in an array as a parameter.

    Please note that if the uploaded image has smaller dimensions than the specified size requested, it will not be resized at all (i.e. will not be up-scaled to fit).

    The ‘post-thumbnail’ size mentioned by @bcworkz, although it is core-provided, it’s usually set by themes. There is no UI in WordPress by default that allows you to change its dimensions.

    The values that can be changed by Settings > Media, correspond to the sizes ‘thumbnail’, ‘medium’ and ‘large’ respectively.
    There’s also a size called ‘full’ which is the actual uploaded file in full resolution.

    An example to wrap up: If you changed the thumbnail size from Settings > Media, then the respective code should be calling the_post_thumbnail(‘thumbnail’)

    Thread Starter hyacinthus

    (@hyacinthus)

    Okay, thanks. The image I uploaded was bigger than any of the “thumbnails” produced. I take it that there is no one “thumbnail” and it’s curious to me that themes can define extra ones. Bear with me. I’m an experienced C and C++ programmer coming from the world of embedded programming. I’m new to working with WordPress but I’ve got NetBeans up and running and can debug now using Xampp.
    So I should look for add_image_size() and see what sizes are possible? Or just look at the ones in the upload folder? I thought each image might have an ID. In the loop in the content_portfolio.php file where these things get chosen for display, the size is called for within the <a> tag as follows

    <a rel="bookmark" class="thumb">
    			<h3><?php the_title() ?></h3>
    			<img />" src="<?php echo esc_url( $image ); ?>" width="200" height="360">
    		</a>

    But it doesn’t seem to have the desired effect on one of the two pics that should be displayed. The second one is fine, but the first is squared and cropped and not the one I want to show.

    [Moderator note: backticks added to denote code. The forum’s parser may have corrupted the code prior to adding backticks]

    • This reply was modified 7 years, 9 months ago by bcworkz.
    Moderator bcworkz

    (@bcworkz)

    The only ID is the attachment ID that applies to the images as a group. Besides the default sizes that Anastis mentioned, any other sizes added are stored in the global $_wp_additional_image_sizes. Themes add other sizes because they may need unique sizes, aspects, or cropping style to fit with the theme’s overall design scheme.

    I’ve added custom sizes to sites because none of the sizes provided by default nicely fit within the post’s content area, they’re all too big, too small, or cropped strangely, and the default sizes all have other purposes where altering that size would cause other problems. Which has nothing to do with featured images, but is another reason for adding a size. For featured images, one of the added sizes is usually perfect as a featured image. The theme’s templates would typically specify this size when using the_post_thumbnail(). Some themes make better use of featured images than others.

    Feel free to set things up so they work for you. Just remember that changes only apply to newly uploaded images. The old sizes persist for existing media unless you use a plugin to regenerate all the image sizes.

    Also, please note that the old generated scaled down versions of images are NOT deleted when regenerating the images, therefore looking into the uploads folder is not a good way to determine the available sizes.

    Now, as far as the code you pasted is concerned, you’ll need to look further up the code, and see what $image is set to.
    This bit is wrong, perhaps it got mangled when you pasted it here:
    <img />" src="<?php echo esc_url( $image ); ?>" width="200" height="360">
    it should be
    <img src="<?php echo esc_url( $image ); ?>" width="200" height="360" />

    Now, the img tag will force the image to display as 200×360, so if $image pulls a different size (one that hasn’t the same aspect ratio) it will most probably appear stretched on some axis.

    The best way to look for theme-provided image sizes, is to do a global search inside the theme files, and look for set_post_thumbnail_size( and add_image_size(
    The first is the one that sets the post-thumbnail size (note that it’s different than thumbnail which is user configurable)
    The other adds a new image size, and its first parameter is the image size name.

    This will help as well, if you haven’t already read it: https://codex.www.ads-software.com/Post_Thumbnails

    Thread Starter hyacinthus

    (@hyacinthus)

    Many thanks to you both. I think I understand enough to get a bit further. There’s a lot yet to learn.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘how to select the thumbnail I want’ is closed to new replies.