Welcome Guest, Not a member yet? Register   Sign In
Any way to compress images
#1

[eluser]gvillavizar[/eluser]
Hello,

In my site my users are uploading pictures, I can limit the file size they're uploading. Is there any way for me to reduce the file size from 1mb to, say 250kb?

Thanks for your help.
#2

[eluser]pistolPete[/eluser]
You can change the quality setting in the image manipulation class: http://ellislab.com/codeigniter/user-gui...e_lib.html
#3

[eluser]gvillavizar[/eluser]
[quote author="pistolPete" date="1235592463"]You can change the quality setting in the image manipulation class: http://ellislab.com/codeigniter/user-gui...e_lib.html[/quote]

Thanks for your reply. That worked like a charm.

Another question, can I load the library more than once with different properties in the same controller.

Like

Code:
if($photo1)
{
$config['source_image'] = '/images/' . $photo1];
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 330;
$config['height'] = 280;
$config['quality'] = '100%';
                
$this->load->library('image_lib', $config);

$this->image_lib->resize();

}

if($photo2)
{
$config2['source_image'] = '/images/' . $photo2];
$config2['create_thumb'] = FALSE;
$config2['maintain_ratio'] = TRUE;
$config2['width'] = 330;
$config2['height'] = 280;
$config2['quality'] = '100%';
                
$this->load->library('image_lib', $config2);

$this->image_lib->resize();

}
#4

[eluser]pistolPete[/eluser]
Don't load it more than once.
Use
Code:
$this->image_lib->clear();
$this->image_lib->initialize($config2);
The user guide states:
Quote:The clear function resets all of the values used when processing an image. You will want to call this if you are processing images in a loop.
#5

[eluser]gvillavizar[/eluser]
[quote author="pistolPete" date="1235596149"]Don't load it more than once.
Use
Code:
$this->image_lib->clear();
$this->image_lib->initialize($config2);
The user guide states:
Quote:The clear function resets all of the values used when processing an image. You will want to call this if you are processing images in a loop.
[/quote]

Perfect, thanks a lot for your help! That solved a lot!




Theme © iAndrew 2016 - Forum software by © MyBB