Woo Hoo...got it <in a round about way>!
Here is what i did. after i writes the uploaded file, then it creats the thumb, i then cloned the thumb process into another process that then re-renders the original file and overwirtes the huge original file.
Example: you upload a 1024x800 size image. I set my code to say any images over say 640px wide reduce them to a new
size of 640px wide (perportioned). so what it does is saves the uploaded file like normal, then creates the thumbnail like normal, then it checks to see if the uploaded file is wider than 640px if not it is done, if it IS wider than 640px it will rerender it to 640px wide and save it over the original. tested and worked. im sure someone will find some fine tuning or corrections but for what we need for now it is a great temporary but working fix. here is the code:
in /wp-admin/admin-functions.php:
just before:
function has_meta($postid) ....
(about line 923ish) past this in:
--------------------------------------------------
function wp_create_smallerimage($file, $max_side, $effect = '') {
// 1 = GIF, 2 = JPEG, 3 = PNG
if (file_exists($file)) {
$type = getimagesize($file);
// if the associated function doesn't exist - then it's not
// handle. duh. i hope.
if (!function_exists('imagegif') && $type[2] == 1) {
$error = __('Filetype not supported. Thumbnail not created.');
}
elseif (!function_exists('imagejpeg') && $type[2] == 2) {
$error = __('Filetype not supported. Thumbnail not created.');
}
elseif (!function_exists('imagepng') && $type[2] == 3) {
$error = __('Filetype not supported. Thumbnail not created.');
} else {
// create the initial copy from the original file
if ($type[2] == 1) {
$image = imagecreatefromgif($file);
}
elseif ($type[2] == 2) {
$image = imagecreatefromjpeg($file);
}
elseif ($type[2] == 3) {
$image = imagecreatefrompng($file);
}
if (function_exists('imageantialias'))
imageantialias($image, TRUE);
$image_attr = getimagesize($file);
// figure out the longest side
if ($image_attr[0] > $image_attr[1]) {
$image_width = $image_attr[0];
$image_height = $image_attr[1];
$image_new_width = $max_side;
$image_ratio = $image_width / $image_new_width;
$image_new_height = $image_height / $image_ratio;
//width is > height
} else {
$image_width = $image_attr[0];
$image_height = $image_attr[1];
$image_new_height = $max_side;
$image_ratio = $image_height / $image_new_height;
$image_new_width = $image_width / $image_ratio;
//height > width
}
$thumbnail = imagecreatetruecolor($image_new_width, $image_new_height);
@ imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1]);
// If no filters change the filename, we'll do a default transformation.
if ( basename($file) == $thumb = apply_filters('thumbnail_filename', basename($file)) )
//original code to rename the picture to ".thumbnail.xxx" , i removed the '.thumbnail' to make this overwrite the original file.
//$thumb = preg_replace('!(\.[^.]+)?$!', __('.thumbnail').'$1', basename($file), 1);
$thumb = preg_replace('!(\.[^.]+)?$!', __('').'$1', basename($file), 1);
$thumbpath = str_replace(basename($file), $thumb, $file);
// move the thumbnail to it's 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");
}
}
}
} else {
$error = __('File not found');
}
if (!empty ($error)) {
return $error;
} else {
return $thumbpath;
}
}
--------------------------------------------------
now in file /wp-admin/inline-uploading.php
just before:
} else {
add_post_meta($id, '_wp_attachment_metadata', array());
}
(About line 95ish) paste the following:
--------------------------------------------------
// this sets the size of how big an image MUST BE to reduce the original to new render size
if ( $imagedata['width'] > 640 ) {
// $max is the width of the new rendered image
$max = 640;
if ($imagedata['height'] > $imagedata['width']) {
$aspect = $imagedata['width']/$imagedata['height'];
$max = $max / $aspect;
}
$thumb = wp_create_smallerimage($file,$max);
if ( @file_exists($thumb) ) {
$newdata = $imagedata;
$newdata['thumb'] = basename($thumb);
update_post_meta($id, '_wp_attachment_metadata', $newdata, $imagedata);
} else {
$error = $thumb;
}
}
--------------------------------------------------
there ya go..
if you want your rerender image to be bigger than the default of 640wide then change the 640 in the following lines to the set width you want on the above code:
// this sets the size of how big an image MUST BE to reduce the original to new render size
if ( $imagedata['width'] > 640 ) {
// $max is the width of the new rendered image
$max = 640;