This repository has been archived by the owner on Dec 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 286
Resizing images
sjlu edited this page Jan 15, 2013
·
2 revisions
Resizing images dynamically to a specific proportion can actually be very strange. A standard configuration is not needed, but a array of parameters is required. It can simply be done like this.
$this->load->library('image_lib');
$config = array(
'image_library' => 'gd2',
'source_image' => '/absolute/path/to/image.png',
'new_image' => '/absolute/path/to/new/image.png',
'maintain_ratio' => true,
'height' => 920,
'width' => 9999999999 // simulate infinity
);
$this->image_lib->initialize($config);
if (!$this->image_lib->resize())
exit('GD2 does not seem to be configured correctly');
$this->image_lib->clear();
- Given the above code, use
999999999999999
to simulate infinity on the dimension you want to dynamically scale to the ratio of the other dimension. - If you're resizing multiple photos, you need to make sure you're clearing the image library or it'll retain the original
source_image
andnew_image
configuration. - http://ellislab.com/codeigniter/user-guide/libraries/image_lib.html