It seems i managed to get this running after several days!
I made a dirty hack and put all code in just one file .....
The file you need to edit is /wp-admin/includes/media.php
at the thop of this file right under <?php
paste this function
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);
$thumb = basename($file);
$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;
}
}
Then in the same file search for the function
function media_handle_upload about 100 lines down if your file is clean
in this function after the line
wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
paste this code
//image resizing
// this sets the size of how big an image MUST BE to reduce the original to new render size
$imagesize = getimagesize($file);
$imagedata = array();
$imagedata['width'] = $imagesize['0'];
$imagedata['height'] = $imagesize['1'];
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;
}
}
I hope it works now just tested it on one picture after posting this solution but it seems to work well..
Image hack for wpmu 1.5.1