@jen – You are correct. Because all of the image crunching is done by WordPress via AJAX after the upload is complete, there is only one image size available. Even if I request the source for a different image size, it returns the only one it has.
Two (maybe more) ways to handle this on your end.
First:
$my_uploaded_image = wp_get_attachment_image_src( $attachment_id );
$post_content = '<img src="' . $my_uploaded_image[0] . '">';
return $post_content;
In this example (pulled partly from the gist I have in this writeup), the array $my_uploaded_image
also has keys [1]
and [2]
that give you the image size. (See codex docs for wp_get_attachment_image_src()). You could then perform some math to resize those values before using them in the IMG element like so:
<img src="$my_uploaded_image[0]" width="$my_image_width" height="$my_image_height">
That at least sizes the IMG element correctly, though it will still have the browser load the full size image in the background, which could be less than ideal.
OR
If you can modify the theme you are using to use featured images (See codex docs for Post Thumbnails), you can add code to template files to display whichever size you want in any given area.
As a way too brief example, something like this in your single.php
template:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1>Post Title: <?php the_title() ?></h1>
<div class="my-post-featured-image">
<?php the_post_thumbnail( 'my-custom-size' ); ?>
</div>
<?php endif; endwhile; ?>
This would give you a display of the post title and the my-custom-size
version of your featured image, which, for the sake of being detailed enough, is defined in functions.php
like so:
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 'my-custom-size', 640, 9999 );
This adds support for a custom size thumbnail that will resize the image to 640 and keep the height automatic.
The second option is my favorite, as this is what the plugin is really intended to help with.
It also allows you to change your mind over time with your photo posts. If you decide next week that you’d rather have images with an 800px width in your layout, it would be a matter of using a different post thumbnail size in your template rather than having to go back and manually change things.
Also (you can tell I like this option), it becomes easier to display different size images depending on the template – archive, search, home, author, etc…
Hope that helps!