Reputation: 16095
Im trying to reduce the quality of uploaded image. Here is my code
$image_config['source_image'] = 'file.jpg';
$image_config['maintain_ratio'] = TRUE;
$image_config['quality'] = '30%';
$image_config['width'] = 1680;
$image_config['height'] = 1050;
$this->load->library('image_lib', $image_config);
$this->image_lib->resize();
The problem is so image has the same quality as the file.jpg etc it is not reduced.
Upvotes: 0
Views: 709
Reputation: 5100
Also check the real mime type. PNG files renamed with JPG extension cannot be reduced by quality.
$info = getimagesize($_filepath);
echo $info['mime'];
Upvotes: 0
Reputation: 11
You just need need to give Numeric value not with "%" sign
Like $image_config['quality'] = '30';
Upvotes: 1
Reputation: 125
I face same problem and I found something in image library file.
system/libraries/image_library.php line 455
if ($this->dynamic_output === FALSE)
{
if ($this->orig_width == $this->width AND $this->orig_height == $this->height)
{
if ($this->source_image != $this->new_image)
{
if (@copy($this->full_src_path, $this->full_dst_path))
{
@chmod($this->full_dst_path, FILE_WRITE_MODE);
}
}
return TRUE;
}
}
This code ignore image rendering if width and height of destination image is the same as the source image. Remove the above code and it should works.
Upvotes: 2
Reputation: 170
Hey Nick, have you tried to display the errors?
if ( ! $this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}
Possible errors I can think of : not giving the correct path to the file or not having installed one of the 3 image libraries (GD/GD2, NetPBM or ImageMagick)
Hope this helps!
Upvotes: 1