I am using the image_lib class in CodeIgniter to re-size images, it works fine; here is my code:
function resizeImage($source_image,$new_image,$width=100,$height=100){
$config['image_library'] = 'gd2';
$config['source_image'] = $source_image;
$config['new_image'] = $new_image;
$config['maintain_ratio'] = TRUE;
$config['width'] = $width;
$config['height'] = $height;
$this->image_lib->initialize($config);
if($this->image_lib->resize()) return true;
else return false;
}
However, what I am trying to achieve, no matter what image it is, landscape, or portrait. Big small. The images are cropped to set dimensions.
Currently, after they are cropped this way, the images come out as different sized thumbs, mainly if it is landscape or portrait. Whereas if you go into a web site such as this you will see that all of the thumbs are exactly the same proportion, width and height.
How can I accomplish this?
Cheers.
EDIT
Excellent tutorial to do exactly this, can be found here:
I am trying to crop and proportionally resize thumbs in CI, as shown here:
OK, then you could crop the images to a square image first, then resize. Take a look here: stackoverflow.com/a/3327424/844726 – swatkins Jun 26 at 13:33
function resizeImg(){
$source_image = base_url().'pic2.jpg';
$config['image_library'] = 'gd2';
$config['source_image'] = $source_image;
$config['new_image'] = $new_image;
$config['maintain_ratio'] = TRUE;
$config['x_axis'] = '10';
$config['y_axis'] = '10';
$config['width'] = $width;
$config['height'] = $height;
$this->image_lib->initialize($config);
}
When I run the script like this:
http://localhost/test/index.php/cronJobs/resizeImg
I get a server error, I guess the script didnt execute.