Posts Tagged “WordPress”

As I was previewing my previous entry, I noticed that the thumbnails that WordPress had created for the attached [jpeg] images were of rather poor quality—they exhibited significant compression artifacts—and they were a little smaller than I would have liked.

The latter problem was a simple fix. The Shift This WordPress Thumbnail Size Plugin creates a new configuration page that allows WordPress admins to specify the max dimensions for thumbnails. (I use 192px.)

The problem of poor jpeg thumbnail quality isn’t as clean to fix. The only solution I could find requires changing a line in the source code. As explained here in the WordPress support forums, the fix requires editing the wp_create_thumbnail function in wp-admin/admin-functions.php.

The following code takes the resampled image data and saves it as a file on the server.

// move the thumbnail to its final destination
if ( $type[2] == 1 ) {
	if (!imagegif( $thumbnail, $thumbpath ) ) {
		$error = __( "Thumbnail path invalid" );
	}
}
elseif ( $type[2] == 2 ) {
	if (!imagejpeg( $thumbnail, $thumbpath ) ) {
		$error = __( "Thumbnail path invalid" );
	}
}
elseif ( $type[2] == 3 ) {
	if (!imagepng( $thumbnail, $thumbpath ) ) {
		$error = __( "Thumbnail path invalid" );
	}
}

The following line from the above code handles jpeg images:

if (!imagejpeg( $thumbnail, $thumbpath ) ) {

The imagejpeg function can take a third argument that specifies the quality (0–100) of the resulting file. If that argument is not provided, it defaults to a value of “about 75″ (according to the PHP manual). I think a value of 90 is more appropriate, so therefore I edited the above line to:

if (!imagejpeg( $thumbnail, $thumbpath, 90 ) ) {

The result is greatly improved; however, as the comparison below demonstrates, it’s still not quite as nice as what I can get using the application that I’ve been using for years to do thumbnails manually—ThumbsUp. The reason is that ThumbsUp provides options for antialiasing and sharpening the thumbnails that it generates.

Example ThumbnailGuitar Hero Cover
Left: WordPress-generated thumbnail (after applying the above hack)—clean, but kinda fuzzy.
Right: thumbnail generated using ThumbsUp—nice & sharp.

Incidentally, the thumbnails on the previous post were all generated using ThumbsUp (to replace the ones that WordPress had originally generated with all the compression artifacts). I had hoped the above hack would keep me from having to do that again; however, it looks like I may have to continue using ThumbsUp as my source for thumbnails.

Comments 8 Comments »

I haven’t blogged in months. I’ve been promising a redesign for ages. Well, the time for action is here. This summer SteveJamieson.com is getting a complete overhaul. So please excuse the mess. I’ve got a blog engine transition to do, databases to upgrade, a photo gallery to install, and templates to design.

Design Preview

[update – 5/28]:

The move of my blog posts from Movable Type to WordPress was quick, simple, and painless. Unfortunately, the Textile (formatting) plugin for WordPress doesn’t seem to support all the shorthand mark-up that the Movable Type plugin does, so I have to reformat all my posts in standard HTML. I also moved my old blog image directory on my server to keep things tidy, so I have to edit all the image URLs as well. On the plus side, this is giving me the opportunity to file everything into categories. Keep an eye on the Uncategorized category to see my progress.

Comments 2 Comments »