Welcome Guest, Not a member yet? Register   Sign In
Image Resizing Questions/Problems
#8

[eluser]Randy Casburn[/eluser]
OK. Try it this way. You're likely to have to compromise on the setting. Most image processing systems have to budge the timeout setting a little if they are processing very large images or insist on processing very large numbers of them all at once.

If there is no way to break up your batch into smaller chunks for processing, then let's at least make things a little more efficient. let's start with this.

Try this. Your script will still time out. I would like you to see what I've done with your code. Note the only two items left "hard coded" in the class are the "70%" quality level and the master dimension of the image. I thought maybe you could pull those out yourself so there was nothing left "hard coded" in your class. In the future if you decide you want the dimensions of the thumbnails (or whatever) to be larger all you have to do is send in different proportions rather than hack to class.

You need to put in some error checking too.

Code:
<?php
$myTest = new Test();

$myTest->largeWidth['width'] = 475;
$myTest->largeHeight['height'] = 450;
$myTest->largeImageDir['dir'] = '/pics/large';
$myTest->mediumWidth['width'] = 300;
$myTest->mediumHeight['height'] = 20;
$myTest->mediumImageDir['dir'] = '/pics/medium';
$myTest->smallWidth['width'] = 200;
$myTest->smallHeight['height'] = 100;
$myTest->smallImageDir['dir'] = '/pics/small';


class Test extends Controller {

    var $config;
    var $largeWidth;
    var $largeHeight;
    var $largeImageDir;
    var $mediumWidth;
    var $mediumImageDir;
    var $smallWidth;
    var $smallHeight;
    var $smallImageDir;

    function Test(){
        $this->__construct();
    }


    function __construct(){
        $this->config['image_library'] = 'gd2';
        $this->config['source_image'] = $f;
        $this->config['create_thumb'] = FALSE;
        $this->config['maintain_ratio'] = TRUE;
        $this->config['master_dim'] = 'height';
        $this->config['quality'] = '70%';
    }
        
    function imageresize(){

        $this->load->helper('file');
        $this->load->library('image_lib');

        foreach(get_filenames('pics/', true) as $f)
            {

            $this->config['width'] = $this->largeWidth;
            $config['height'] = $this->largeHeight;
            $config['new_image'] = $this->largeImageDir;
            $this->image_lib->initialize($this->config);// <- EDIT

            $this->image_lib->resize();

            $this->config['width'] = $this->mediumWidth;
            $config['height'] = $this->mediumHeight;
            $config['new_image'] = $this->mediumImageDir;
            $this->image_lib->initialize($this->config);// <- EDIT

            $this->image_lib->resize();
            
            $this->config['width'] = $this->smallWidth;
            $config['height'] = $this->smallHeight;
            $config['new_image'] = $this->smallImageDir;
            $this->image_lib->initialize($this->config);// <- EDIT
            $this->image_lib->resize();

        /* You need to ensure you have your resized images befor you delete
           your original */    
            unlink($f);
            }

            echo 'Job Done';

    }
}
?&gt;

Have fun.

Randy


Messages In This Thread
Image Resizing Questions/Problems - by El Forum - 07-09-2008, 04:54 PM
Image Resizing Questions/Problems - by El Forum - 07-09-2008, 05:01 PM
Image Resizing Questions/Problems - by El Forum - 07-09-2008, 05:29 PM
Image Resizing Questions/Problems - by El Forum - 07-09-2008, 08:27 PM
Image Resizing Questions/Problems - by El Forum - 07-11-2008, 11:21 AM
Image Resizing Questions/Problems - by El Forum - 07-11-2008, 12:34 PM
Image Resizing Questions/Problems - by El Forum - 07-11-2008, 12:45 PM
Image Resizing Questions/Problems - by El Forum - 07-11-2008, 01:35 PM
Image Resizing Questions/Problems - by El Forum - 07-11-2008, 01:51 PM
Image Resizing Questions/Problems - by El Forum - 07-11-2008, 01:52 PM
Image Resizing Questions/Problems - by El Forum - 07-11-2008, 02:03 PM
Image Resizing Questions/Problems - by El Forum - 07-11-2008, 03:29 PM



Theme © iAndrew 2016 - Forum software by © MyBB