Okay, here’s a solution, but a partial one. Certainly enough to start actually recreating inline-uploading.php in a sane way (as a plugin in a folder with multiple files that encapsulate the various functionality), and enough to handle the issue at hand.
So you need a plugin of some variety that does this:
function new_inline() {
global $post_ID;
$uploading_iframe_ID = (0 == $post_ID ? $temp_ID : $post_ID);
$uploading_iframe_src = "ii-inline-uploading.php?action=view&post=$uploading_iframe_ID";
return get_bloginfo('url') . '/wp-content/plugins/' . $uploading_iframe_src;
}
add_filter('uploading_iframe_src', 'new_inline');
ii-inline-uploading.php is just inline-uploading.php copied into the plugins directory. You don’t have to rename it. Anyway, now you can hack at this file (this is how you’d make it sane, if you were so inclined). For our purposes, we’ll just hack at it in a somewhat unsophisticated way.
First, you need to change the require_once(...)
call at the top so that our new uploading file knows what from what. This line should now look like:
define('ABSPATH','/path/to/wordpress');
require_once(ABSPATH . 'wp-admin/admin.php');
Now, you’ll want to replace the if
statement that starts if ( $imagedata['width'] * $imagedata['height'] < 3 * 1024 * 1024 ) {
(line 84 or thereabouts, ymmv). Basically, you just need to replace the logic with a different calculation scheme for resizing:
if ( $imagedata['width'] * $imagedata['height'] < 3 * 1024 * 1024 ) {
$max = 165;
if ($imagedata['height'] > $imagedata['width']) {
$aspect = $imagedata['width']/$imagedata['height'];
$max = $max / $aspect;
}
$thumb = wp_create_thumbnail($file,$max);
if ( @file_exists($thumb) ) {
$newdata = $imagedata;
$newdata['thumb'] = basename($thumb);
update_post_meta($id, '_wp_attachment_metadata', $newdata, $imagedata);
} else {
$error = $thumb;
}
}
} ...
Okay, one last thing, how does this scheme work? Well, you just set a max width ($max=165
). If the image is taller than it is wide, then you have to scale the max because wp_create_thumbnail
wants a “largest side”. In the taller-than-wide scenario, that means the height will get scaled to your preferred max, and the width will be less. You adjust the max side variable by dividing by the aspect ratio (width * height). In fancy math terms, the inverse of the aspect ratio is the scaling factor which lets you adjust the height to achieve the desired width.
Again, this is pretty much a brute force attack and there might be some problems, but it works, suggests some other possibilities, and doesn’t require you to hack away at core WordPress files.