I need a simple script or in-line code that can resize a thumbnail image to the proper size for my WordPress theme.
For example, I need thumbnails that are standardized to 192x120px. However, when I pull an automatic thumbnail from a YouTube video RSS feed, the image is 120x90px.
An example of the code to display the thumbnail is:
<div class=”thumbnail”>
<a href=”<?php the_permalink() ?>” title=”<?php the_title() ?>”>
<img width=”192″ height=”120″ style=”background: url(<?php $key=”thumbnail”; echo get_post_meta($post->ID, $key, true); ?>) center no-repeat” class=”thumb” src=”<?php bloginfo(‘template_url’); ?>/images/zoom.png” alt=”<?php the_title() ?>” /></a>
</div>
As you can see, the page loads the video thumbnail as a background image within the DIV and then puts a transparent image (zoom.png) on top. This puts a floating triangle over the top of the image to look like a “play” button. (an example of this effect is on the homepage of FDAWarning.org).
I need a script that will take the image that has been saved (approx 120×90 dimensions, although it is variable) and automatically scale that image as needed to fill the space. The image should scale evenly (height and width) to 192×120 and trim any part of the image that extends outside the box.
For example, the YouTube thumbnail is stored as 120x90px. So, the script would expand this image to 192x144px and then trim off 12px from the left and right (24 extra pixels, evenly split between left/right). So, the resulting image will display as 192×120 in my theme.