Reputation: 989
I am getting a black area to handle this with CI, the image have 950x720
the first resize is ok $this->resize($data['upload_data']['full_path'], 220, 200, true, false); but in the second, the error appear
code on gist: https://gist.github.com/mateuspv/48ba464a557da9bbdf10
<?php
/**
* resize
* @param string $path [description]
* @param int $width [description]
* @param int $height [description]
* @param boolean $thumb [description]
* @param boolean $ratio [description]
*/
private function resize($path, $width, $height, $thumb, $ratio) {
$config['image_library'] = 'GD2';
$config['source_image'] = $path;
$config['maintain_ratio'] = $ratio;
$config['create_thumb'] = $thumb;
$config['encrypt_name'] = TRUE;
$config['width'] = $width;
$config['height'] = $height;
$this->image_lib->clear();
$this->image_lib->initialize($config);
$this->image_lib->resize();
if (!$this->image_lib->resize()) {
die($this->image_lib->display_errors());
}
}
//...
/**
* TODO ~
*/
$data = array('upload_data' => $this->upload->data());
$this->resize($data['upload_data']['full_path'], 220, 200, true, false);
$this->resize($data['upload_data']['full_path'], 450, 450, false, false);
Upvotes: 0
Views: 1113
Reputation: 1464
I think when you call function first time the script modify image itself and make it to 220px by 200px. and when you call function second time it take small image and resize it to 450px by 450px. this may be the error.. try to save first thumbnail to new destination file. try below code.
<?php
/**
* resize
* @param string $path [description]
* @param int $width [description]
* @param int $height [description]
* @param boolean $thumb [description]
* @param boolean $ratio [description]
*/
private function resize($path, $width, $height, $thumb, $ratio) {
$config['image_library'] = 'GD2';
$config['source_image'] = $path;
$config['new_image'] = PATH_TO_NEW_IMAGE;
$config['maintain_ratio'] = $ratio;
$config['create_thumb'] = $thumb;
$config['encrypt_name'] = TRUE;
$config['width'] = $width;
$config['height'] = $height;
$this->image_lib->clear();
$this->image_lib->initialize($config);
$this->image_lib->resize();
if (!$this->image_lib->resize()) {
die($this->image_lib->display_errors());
}
}
//...
/**
* TODO ~
*/
$data = array('upload_data' => $this->upload->data());
$this->resize($data['upload_data']['full_path'], 220, 200, true, false);
$this->resize($data['upload_data']['full_path'], 450, 450, false, false);
Change PATH_TO_NEW_IMAGE to your destination file path. Hope this helps.
Upvotes: 1