I am using ImageMagick library in CodeIgniter for re-sizing and rotating image using image library. But its generating error. The error is -"The path to your image library is not correct. Please set the correct path in your image preferences."
$config = array();
$config['image_library'] = 'ImageMagick';
$config['source_image'] = $file;
$config['new_image'] = $file;
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 50;
$config['height'] = 50;
$this->image_lib->initialize($config);
if ( !$this->image_lib->resize())
{
echo "resize -".$this->image_lib->display_errors();
}
$this->image_lib->clear();
Below has given me expected result. Hope you will also get same.
$this->load->library('image_lib');
//For resizing of image in size of dilog
$config['image_library'] = 'ImageMagick';
$config['library_path'] = 'C:\\ImageMagick\\';
$config['source_image'] = $source_filepath;
$config['new_image'] = $new_filepath;
$config['width'] = 128;
$config['height'] = 128;
$config['quality'] = '100%';
$config['maintain_ratio'] = TRUE;
$this->image_lib->initialize($config);
if (! $this->image_lib->resize()) {
$error_msg = $this->image_lib->display_errors();
print_r($error_msg);
}
else {
echo "Done";
}
Here
$config['library_path'] = 'C:\\ImageMagick\\';
is the path for windows where your imageMagick application is installed.(Try to install in such a folder to which we can easily map it for library path).
Change the image library to :
$config['image_library'] = 'ImageMagick';
& other all configuration is remains same.
I think you are not giving correct path basically imagemagick is installed somewhere ideally in /user/bin. When I worked I use to give like this
imageMagickConvert = /usr/bin/convert
imageMagickComposite = /usr/bin/composite
$config['library_path'] = '/usr/bin';
add this line in your config.
Related
I have added the code for resizing images in codeigniter.
$configs['image_library'] = 'gd2';
$configs['source_image'] = './userpics/'.$new_name;
$configs['new_image'] = './userpics/userthumb/'.$new_name;
$configs['create_thumb'] = FALSE;
$configs['maintain_ratio'] = TRUE;
$configs['quality'] = '100';
$configs['width'] = 80;
$configs['height'] = 80;
But images are coming in 80*45 or 80*60. Please let me know any solution so that i can show in proper dimensions.
pl refer
https://ellislab.com/codeigniter/user-guide/libraries/image_lib.html
maintain_ratio : TRUE/FALSE - Specifies whether to maintain the original aspect ratio when resizing or use hard values.
$this->load->library('image_lib');
$config['image_library'] = 'gd2';
$config['source_image'] = "Mention your source location here";
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['height'] = "New Width";
$config['width'] = "New Height";
$config['new_image'] = "destination location";//you should have write permission here..
$this->image_lib->initialize($config);
$this->image_lib->resize();
Check This
I want to use imageMagick for image processing. Now I have installed ImageMagick ImageMagick-6.8.4-10-Q16-x64-dll.exe but still I face the following error:
Image processing failed. Please verify that your server supports the chosen protocol and that the path to your image library is correct.
My code is -
$config = array();
$config['image_library'] = 'ImageMagick';
$config['source_image'] = $file;
$config['new_image'] = $file;
$config['library_path'] = '/usr/local/bin';
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 50;
$config['height'] = 50;
$this->image_lib->initialize($config);
if ( !$this->image_lib->resize())
{
echo "resize -".$this->image_lib->display_errors();
}
$this->image_lib->clear();
Wait. I assumed you are using Windows (as you installed .exe ), but your path is a Linux path (/usr/local/bin). Double check your installation path.
Below has given me expected result. Hope you will also get same.
$this->load->library('image_lib');
//For resizing of image in size of dilog
$config['image_library'] = 'ImageMagick';
$config['library_path'] = 'C:\\ImageMagick\\';
$config['source_image'] = $source_filepath;
$config['new_image'] = $new_filepath;
$config['width'] = 128;
$config['height'] = 128;
$config['quality'] = '100%';
$config['maintain_ratio'] = TRUE;
$this->image_lib->initialize($config);
if (! $this->image_lib->resize()) {
$error_msg = $this->image_lib->display_errors();
print_r($error_msg);
}
else {
echo "Done";
}
Here
$config['library_path'] = 'C:\\ImageMagick\\';
is the path for windows where your imageMagick application is installed.(Try to install in such a folder to which we can easily fingd the path upto it).
Change the image library to :
$config['image_library'] = 'ImageMagick';
& other all configuration is remains same.
I'm trying to resize and rotate a image.
At the moment it's only resizing the image, but not rotate it.
Here is the code, hope someone have a solution or something :-)
$config['image_library'] = 'gd2';
$config['source_image'] = $data['full_path'];
$config['new_image'] = $data['file_path'].'thumbs/'.$data['file_name'];
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 235;
$config['height'] = 235;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
$this->image_lib->clear();
$config['create_thumb'] = FALSE; //No thumbnail
$config['source_image'] = $data['file_path'].'thumbs/'.$data['file_name']; //full path for the source image
$config['rotation_angle'] = '180';//
$this->load->library('image_lib',$config);
//Rotate the image
$this->image_lib->rotate();
After
$this->image_lib->clear();
add:
$config = array() to re-initialise your config array.
After clearing the configuration, don't reload the library, reinitialize it:
$this->image_lib->clear();
$config=array();
$config['image_library'] = 'gd2';
$config['source_image'] = $data['file_path'].'thumbs/'.$data['file_name'];
$config['rotation_angle'] = '180';
$this->image_lib->initialize($config); // reinitialize it instead of reloading
$this->image_lib->rotate();
This is the only solution that finally worked for me. Just re-initialising $config did not work out in CodeIgniter 2.2.0.
Make sure you recreate the $config before sending it again.
Otherwise you might end up sending values you don't want to send.
At the moment rotate() gets a $config like this:
$config['image_library'] = 'gd2';
$config['new_image'] = $data['file_path'].'thumbs/'.$data['file_name'];
$config['maintain_ratio'] = TRUE;
$config['width'] = 235;
$config['height'] = 235;
$config['create_thumb'] = FALSE; //No thumbnail
$config['source_image'] = $data['file_path'].'thumbs/'.$data['file_name']; //full path for the source image
$config['rotation_angle'] = '180'; //
I need to make two images of a single loaded picture. This images must have fixed width, - 180 and 300 pixels.
At the bottom of my current results. This function can resize and create just one of two images. Everybody failed on second image, I trying whole day, but I'm can't find reason. Need help.
$this->_resize($data['upload_data']['file_name'], 300);
$this->_resize($data['upload_data']['file_name'], 180);
private function _resize($file_name, $size) {
$config['image_library'] = 'gd2';
$config['source_image'] = 'img/upload/' . $file_name;
$config['dest_image'] = base_url() . 'img/';
$config['create_thumb'] = TRUE;
$config['thumb_marker'] = '_' . $size;
$config['maintain_ratio'] = FALSE;
$config['width'] = $size;
$config['height'] = $size;
$this->load->library('image_lib', $config);
$result = $this->image_lib->resize();
$this->image_lib->clear();
return;
}
I'm use CodeIgniter 2.02
Dont load image_lib multiple times. Add image_lib in autoload libs and change
$this->load->library('image_lib', $config);
to
$this->image_lib->initialize($config);
This could help you, from user guide
A good practice is use the processing
function conditionally, showing an
error upon failure, like this:
if ( ! $this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}
Nill
Think that problem takes place because on the first run your script moves initial file to another folder. Try to use:
$config['new_image'] = base_url() . 'img/';
instead of
$config['dest_image'] = base_url() . 'img/';
I found myself this problem. In my case, I put the image source and new_image without base_url or REAL_PATH:
public function create_thumbnail($file_name='2012_02_23_15_06_00_1.jpg'){
$this->layout = false;
$image_url = PATH_TO_IMAGE_ARTICLE.DIRECTORY_SEPARATOR;
$config['image_library'] = 'gd2';
$config['source_image'] = 'assets/img/content/article/'.$file_name;
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 210;
$config['height'] = 160;
$config['new_image'] = 'assets/img/content/article/thumb/thumb_' . $file_name;
$this->load->library('image_lib', $config);
if(!$this->image_lib->resize())
{
echo $this->image_lib->display_errors();exit;
}
return TRUE;
}
See?
you don't put
$config['new_image'] = base_url().'assets/img/content/article/thumb/thumb_' . $file_name;
but
$config['new_image'] = 'assets/img/content/article/thumb/thumb_' . $file_name;
Following is the code which resize the image, but here i am not able to resize the image
function processHome(){
$this->load->library('image_lib');
$img_path = base_url().'img/image/50X50/ori.jpeg';
$config['image_library'] = 'gd2';
$config['source_image'] = $img_path;
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 50;
$config['height'] = 50;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
if ( ! $this->image_lib->resize()){
echo $this->image_lib->display_errors();
}
echo "No error";
exit;
$this->load->view('index', $data);
}
For a start, remove the
$this->load->library('image_lib');
at the beginning - you only need to load the library once, and only after you set the parameters.
Then, give the relative/server path to your image folder, instead of the url - as in, no base_url().
Finally, check the permissions for the folder the image is in - it must be readable/writable by all, and php should be allowed to create new files.
I guess that's all.