[eluser]megabyte[/eluser]
here's the code I'm using.
Code:
function _upload_image(){
if(!empty($_FILES))
{
$this->load->library('upload');
$this->load->library('image_lib');
$config['upload_path'] = './photos/';
$config['allowed_types'] = 'jpg|jpeg|gif|avi';
$config['encrypt_name'] = 'TRUE';
$this->upload->initialize($config);
$this->upload->do_upload();
$resarr = $this->upload->data();
$file = $resarr['file_name'];
$this->setMemoryForImage($resarr['full_path']);
if($file != '')
{
$config['image_library'] = 'GD2';
//$config['create_thumb'] = TRUE;
$config['source_image'] = $resarr['full_path'];
$config['maintain_ratio'] = TRUE;
$config['width'] = 800;
$config['height'] = 800;
$config['master_dim'] = 'width';
$this->image_lib->initialize($config);
$this->image_lib->resize();
echo $this->image_lib->display_errors();
}
echo $this->upload->display_errors();
//print_r($resarr);
}
}
function setMemoryForImage( $filename ){
$imageInfo = getimagesize($filename);
$memoryLimitMB = 0;
$MB = 1048576; // number of bytes in 1M
$K64 = 65536; // number of bytes in 64K
$TWEAKFACTOR = 8; // Or whatever works for you
$memoryNeeded = round( ( $imageInfo[0] * $imageInfo[1]
* $imageInfo['bits']
* $imageInfo['channels'] / 8
+ $K64
) * $TWEAKFACTOR
);
//ini_get('memory_limit') only works if compiled with "--enable-memory-limit" also
//Default memory limit is 8MB so well stick with that.
//To find out what yours is, view your php.ini file.
$memoryLimit = 8 * $MB;
if (function_exists('memory_get_usage') &&
memory_get_usage() + $memoryNeeded > $memoryLimit)
{
$newLimit = $memoryLimitMB + ceil( ( memory_get_usage()
+ $memoryNeeded
- $memoryLimit
) / $MB
);
ini_set( 'memory_limit', $newLimit . 'M' );
return true;
}
else{
return false;
}
}
I hope this helps out others like its helped out me.