Bigger Thumbnails

1 Comment
Technology, Wordpress

I figured I’d make a note of this here, since it’s something I ran into with WordPress 2.03, and likely a WordPress 2.04 is going to be released soon enough. By default when you upload an image via WordPress’ posting interface, it will create a thumbnail image if the image is larger than a certain size (128×128). This default size is quite small, and WordPress will, by default, insert the thumbnailed version of the image into your posts rather than the full-size version. Images that small are barely even distinguishable, but at the same time I figured that I might sometimes be using source images that are huge (1024×768+) and thus require resizing. Even if an image is being visually sized to fit my layout, such large images would still have to be loaded in full for any people viewing the page, and editing the image’s visible proportions individually can be a hassle.

To resolve these issues I made some changes to my inline-uploading.php file so that thumbnail images are twice as large — Assured to fit virtually any layout, and yet large enough to be distinguishable. It cuts down on work for me on a number of fronts, and cuts down on loading times as the thumbnails are being displayed at actual-size.

$id = wp_insert_attachment($attachment, $file, $post);

if ( preg_match('!^image/!', $attachment['post_mime_type']) ) {
// Generate the attachment's postmeta.
$imagesize = getimagesize($file);
$imagedata['width'] = $imagesize['0'];
$imagedata['height'] = $imagesize['1'];
list($uwidth, $uheight) = get_udims($imagedata['width'], $imagedata['height']);
$imagedata['hwstring_small'] = "height='$uheight' width='$uwidth'";
$imagedata['file'] = $file;

add_post_meta($id, '_wp_attachment_metadata', $imagedata);

if ( $imagedata['width'] * $imagedata['height'] < 3 * 1024 * 1024 ) { if ( $imagedata['width'] > 256 && $imagedata['width'] >= $imagedata['height'] * 4 / 3 )
$thumb = wp_create_thumbnail($file, 256);
elseif ( $imagedata['height'] > 256 )
$thumb = wp_create_thumbnail($file, 256);

One Response

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>