The MU forums have moved to WordPress.org

Image file resize at upload.... (45 posts)

  1. indeepdark
    Member
    Posted 18 years ago #

    Hi

    Seems that this code is no longer valid...

    I try it today (errr... night) and it gave me an error. There is no wp_create_smallerimage function, and $imagedata seems to have became $image_data.

    Fatal error: Call to undefined function: wp_create_smallerimage() in .../wp-admin/upload-functions.php on line 255

    Any idea ?

    Thanks

  2. indeepdark
    Member
    Posted 18 years ago #

    Nobody have a clue to solve this problem ?

    Thanks

  3. indeepdark
    Member
    Posted 18 years ago #

    Well I don't like acting like this, but... up !

  4. theapparatus
    Member
    Posted 18 years ago #

    You don't even tell us what version of mu you're running.

    http://codex.wordpress.org/Debugging_WPMU

    If you've just upgraded or recently done so, looks like you may have skipped a file. That call is coming from somewhere within your install but a quick check shows that no call exists within the 1.3 version.

  5. indeepdark
    Member
    Posted 18 years ago #

    Nope, I've tried this hack after upgrading to 1.2.5...

    And the call is in the file I've hack -- upload-functions.php --, and I didn't found any similar function in it.

  6. TypoDemon
    Member
    Posted 18 years ago #

    Hello!
    I'm using the latest version of Wordpress (I belive 2.3.3) as of November 30th, 2007.

    This actually fixed my problem, however, the file was named "upload" in the wp-admin/includes. The script in question as to where to put it under is right at the top. You just have to read and deduct that it still goes after "id" tag :).

  7. andrea_r
    Moderator
    Posted 18 years ago #

    Some files did get shuffled around from 1.2.5 to 1.3. Same as in regular WP.

  8. bloggus
    Member
    Posted 17 years ago #

    Anyone got his hack working in 1.3.3 ?

  9. Pegan
    Member
    Posted 17 years ago #

    I hope we can bring back life to this post and update the code so it works in latest wpmu 1.5.1 if im correct and based on worpdress 2.5.1. The code is quite different now and im having a hard time finding out how to make the changes needed to get it working.

    Im running a swedish blog for parents who has childrens with various diceases our kid has HLHS only half his heart works. Thoose parents live a long time at Ronald MC Donalds house and has to blog from public computers and often they dont even know how to resize a picture or the tools isnt avaliable at the computers.

    I hope someone can shed some light over this hack so it will be easier for the parents to blog.

    Cheers!
    Andreas Hanfelt

  10. Pegan
    Member
    Posted 17 years ago #

    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

  11. Pegan
    Member
    Posted 17 years ago #

    Here is the updated file for 2.6.1 wpmu it defaults to 640 px width.. drop in /wp-admin/includes/

    link:
    http://sites.google.com/a/hanfelt.se/wpmu/Home/wpmu

  12. Ovidiu
    Member
    Posted 17 years ago #

    doesn't one of the other wordpress plugin work with wpmu? something like flexible manager or image manager maybe?

    I think its kind of restrictive to not give the user a choice to upload bigger images.

    I know 99% of them are not aware what their brand new 12 mega pixel camera produces and certainly do not know that 5MB is way too much for a picture on a website :-) but still, you have to give them a choice I think.

  13. burtonkent
    Member
    Posted 17 years ago #

    I used the google code from two posts ago, and the full size images came out black. Thumbnails and medium size were fine. I'm running wpmu 2.6.3. Also, the error messages were:

    Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file in /home2/acupun/public_html/wpmu/wp-admin/includes/media.php on line 28

    Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: '/home2/acupun/public_html/wpmu/wp-content/blogs.dir/25/files//misc_080.jpg' is not a valid JPEG file in /home2/acupun/public_html/wpmu/wp-admin/includes/media.php on line 28

    Warning: imageantialias(): supplied argument is not a valid Image resource in /home2/acupun/public_html/wpmu/wp-admin/includes/media.php on line 35

    Sure would be nice to limit photo sizes. I'm trying to allow my users to use Lightbox 2, which doesn't work well when the picture is 2x the size of the browser window.

  14. brennino
    Member
    Posted 17 years ago #

    Hi,
    I have the same problem and I find this...

    http://wordpress.org/extend/plugins/resize-at-upload/

    I use wordpress Mu 2.6.

    The plugin resize original image at upload and drop the original.

    I try this in the plugin directory and it works after activation. Don't know in mu-plugins dir.

    I hope that it helps

  15. photolord
    Member
    Posted 17 years ago #

    I actually want to specify size and compression for uploads and not allow users to control that. I wanted to use the Monotone theme and size. Until I can limit photo sizes, it could be costly on hosting to set-up a MU photosite. Any ideas what I would put and where?

    Maximum width 840 pixels

    Minimum width 560 pixels

    As well as maybe include a slight compression that I could define and check results.

    Thanks for any help.

About this Topic

  • Started 19 years ago by palkat
  • Latest reply from photolord