开发者

Resize Image to Fit Dimensions Completely (Codeigniter)

开发者 https://www.devze.com 2023-03-19 02:55 出处:网络
I am using the image library in Codeigniter to resize my image. I notice that CI only resizes the image to fit inside the specified dimensions: A 5开发者_运维技巧0px by 50px image resized to fit a 30p

I am using the image library in Codeigniter to resize my image. I notice that CI only resizes the image to fit inside the specified dimensions: A 5开发者_运维技巧0px by 50px image resized to fit a 30px by 20px box will be resized to 20px by 20px and leaves a black area for the empty space.

What I want is to resize such that the resize image fills the entire 30px by 30px space with the excess portion being cropped out.

Is this possible in Codeigniter?


I think you'll need to resize the image first, choosing either width or height as the "master" dimension, then crop it.

I haven't tested this code, but give it a shot. If nothing else, it should give you the idea.

$config['source_image'] = '/path/to/image/mypic.jpg';

$config['width'] = 30;
$config['height'] = 0; // No restraint on height
$this->load->library('image_lib', $config);
$this->image_lib->resize();

$config['x_axis'] = 30; // Same width as before
$config['y_axis'] = 20; // Crop to height
$this->image_lib->initialize($config);
$this->image_lib->crop();

You may want to try to center the crop dimensions instead. Whichever way you choose to do it, the image needs to be cropped at some point.

I should note that I'm not sure if $config['height'] = 0 is the right way to ignore height, it might have to be FALSE, a really high number, or removed altogether (haven't worked with the CI image lib in a while).

0

精彩评论

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