[wp-hackers] Image Upload Resizing in WordPress 3.0

Mike Schinkel mikeschinkel at newclarity.net
Wed Sep 22 01:14:22 UTC 2010


On Sep 21, 2010, at 4:23 PM, David Morris wrote:
> I see now. That makes sense. The sticking point with one of the people on my
> team is that the Scissors plugin would not allow a blogger to EVER use the
> full size image in a post by accident, and WP 3.0 does.
> 
> We are running ~500 blogs, and I guess they don't trust the bloggers to
> insert the proper image size into their posts, and in 2.9.1 scissors
> prevented that from happening.
> 
> Thanks so much for your reply,

Hi Dave,

There is a hook called "wp_handle_upload" that is called right after an upload for (at least some?) file uploads.  It gets two parameters:

#1: array(
'file' => $filepath, 
'url' => $fileurl, 
'type', => $mimetype 
), 
#2: 'upload'

There are several functions for addressing image size in WordPress and PHP but image_make_intermediate_size($filepath,$width,$height) might be what you need. First find out of the file is too big using getimagesize():

list($width, $height, $type, $attr) = getimagesize( $filepath );

If so resize it to your max size (this example assumes your max would be 640x480): 

image_make_intermediate_size($filepath,640,480)

Hope this helps.

-Mike



More information about the wp-hackers mailing list