Log in | Register | Lost password

Bottom
resize uploaded images with Xinha Extended File Manager
  • Posted: 07.09.2005, 00:11
     
    Converted
    rank:
    12
    registered:
     March 2009
    Status:
    offline
    last visit:
    Posts:
    0
    Continued some work on Xinha, and found a way to automatically resize all uploaded images. Want to share that code with you.

    add near line 447 in guppy/xinha/plugins/ExtendedFileManager/Classes/ExtendedFileManager.php
    after:

    Code

    $result = Files::copyFile($file['tmp_name'], $path, $file['name']);

    the following code:

    Code

    //////////////////Start Image Resize Hack ///////////

    /// for extended file manager by apollo13 9.2005



    $maxwidth=$this->config['maxwidth'];

    $maxheight=$this->config['maxheight'];

    $quality= $this->config['quality'];



    // check if vars are set

    if ($maxwidth or $maxheight or $quality)

    {

    // get vars

    require_once('Transform.php');

    $img=Image_Transform::factory(IMAGE_CLASS);

    $fullpath=$path.$result;

    $img->load($fullpath);

    $or_width=$img->img_x;

    $or_height=$img->img_y;

    if (!$quality)

    {

    $quality=100;

    }



    ////////////////////////////////

    // new sizes after maxwidth restriction



    // prevent enlargement

    if ($or_width<$maxwidth)

    {

    $maxwidth='';

    }



    // do the calculations

    if ($maxwidth)

    {

    $sizechanged=true;

    $new_height = round(($maxwidth / $or_width) * $or_height, 0);

    $new_width = $maxwidth;

    }

    else

    {

    $new_width = $or_width;

    $new_height = $or_height;

    }



    ////////////////////////////////

    // new sizes after maxheight restriction



    // prevent enlargement

    if ($new_height<$maxheight)

    {

    $maxheight='';

    }



    //do the calculations

    if ($maxheight)

    {

    $sizechanged=true;

    $final_width = round(($maxheight / $new_height) * $new_width, 0);

    $final_height= $maxheight;

    }

    else

    {

    $final_width = $new_width;

    $final_height = $new_height;

    }



    if ($sizechanged or $quality<100)

    {

    // start operations

    $img->resize($final_width,$final_height);

    $img->save($fullpath,'',$quality);

    $img->free();

    }

    }



    ////////// END RESIZE HACK //////////////


    After doing so you can go to the config.inc.php of the Extended file manager and add your configurations as you like it:

    Code

    $IMConfig['maxwidth']=250;

    $IMConfig['maxheight']=350;

    $IMConfig['quality']=85;


    This resizes uploaded pictures with width of more than 250 pixels width or more than 350 pixels height and saves pictures in a quality of 85%(jpg compression).

    Have fun!



Template courtesy of Designs By Darren.