开发者

image resize in runtime with codeigniter(php)

I have uploaded an image with the resolution 1600x1200. How can I show users 60x60 and 200x200 without creating thumbnails and uploading again. (like phpthumb library) in CodeIgniter?开发者_开发知识库


http://codeigniter.com/forums/viewthread/155086/

That's the timThumb controller for CI.


Codeigniter comes with its own image library which can resize images. This example is from the documentation, just edit the $config variable:

$config['image_library'] = 'gd2';
$config['source_image'] = '/path/to/image/mypic.jpg';
$config['new_image'] = '/path/to/new/image.jpg';
$config['maintain_ratio'] = TRUE;
$config['width'] = 75;
$config['height'] = 50;

$this->load->library('image_lib', $config);

$this->image_lib->resize();

You can also create thumbnails dynamically (that is, without saving them to the hard drive) but that requires a lot of memory so I would discourage that.

The image class can also crop the image if you need that. I use it to create thumbnails in the application I am currently working on...

Visit the documentation: http://codeigniter.com/user_guide/libraries/image_lib.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜