views:

40

answers:

3

Hi Guys,

I'm using WordPress 3.0 and the 'the_post_thumbnail' function to resize my images. The problem is that the function doesn't resize to exact dimensions when you don't specify a square image.

// Works fine
add_image_size('my-image-size',100, 100, true);

// Image is only resized to width or height, not both
add_image_size('my-image-size',265, 182, true);

I'm pretty sure this is a bug, as I feel the image should be cropped to both dimensions to make an exact size. I could just edit the 'image_resize_dimensions' function in media.php, but I'm wondering if there is a better way, some way to override that function with my own?

Thanks!

Darren.

A: 

You can't override functions in PHP. You'll get a fatal error if you attempt to define a function with the same name within the same scope. Apparently you can use this: override_function() to override built-in functions. Not sure about ones define in other files though.

You could define another function (ie: add_image_size2) however and refactor the code to call that instead, but you'll end up modifying a lot more of the code than you would by just editing the function.

NullUserException
I know that in WordPress you can add hooks and filters, I'm just wondering if there is something like that for this.
dazhall
+1  A: 

Mark JaQuith has an article recommended by the Codex page on the_post_thumbnail function. It discusses using a different function "set_post_thumbnail_size() to change image sizes.

    set_post_thumbnail_size( 50, 50, true ); 
    // 50 pixels wide by 50 pixels tall, hard crop mode

It has a crop flag argument that you can pass to perform a hard crop to the exact dimensions you specify, or a soft crop, which works the way you are experiencing. I know the article discusses WP 2.9 specifically, but it might help.

kevtrout
Yeah but the problem is that hard cropping isn't working correctly.
dazhall
A: 

In most of my theme development prior to 3.0 I used the timthumb plugin with much success. As i also found the built-in functions lacking. You can find the info here: http://bit.ly/yl1C.

h3r2on
Cheers, I've used that plugin in combination with this little gem to just get the URI of the image and then resize it with phpTumb. Simples!http://www.leewillis.co.uk/getting-url-post-thumbnails-wordpress/
dazhall