I have install ImageMagick still i face error in image library - php

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.

Related

How to resize image in codeigniter according to given dimensions

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

how to resize image size(quality) with codeigniter image_lib

we are creating an application which allows image upload, now we want to reduce the image size to reduce the page load time, now this is the code i'm using, it doesn't work, image size remains 100% it doesn't reduce, please help maybe i'm missing something or i'm doing something wrong
if(!empty($_FILES['image_field']['name']))
{
$config['upload_path'] = 'image_folder';
$config['allowed_types'] = 'jpg|png';
$config['max_size'] = '262144';
$config['file_name'] = 'my_image_name';
$this->load->library('upload',$config);
if(!$this->upload->do_upload('image_field'))
{
$this->session->set_flashdata('error','<div class="alert alert-warning">Something went wrong...try again...</div>');
redirect('Controller/function_name');
}
else
{
$type = array('image/png'=>'png','image/jpg'=>'jpg','image/jpeg'=>'jpg');
$config['image_library'] = 'gd2';
$config['source_image'] = base_url().'image_folder'.$config['file_name'].'.'.$type[$_FILES['image_field']['type']];
$config['quality'] = '50%';
$this->load->library('image_lib', $config);
$this->image_lib->resize();
// save to database
}
}
i'm using codeigniter 3.0
You should use without % as integer like that:
$config['quality'] = 50;
$config['image_library'] = 'gd2';
$config['quality'] = 60;
works great adjust the quality and check the image file size it save. will be different.
I also had to set my image_library parameter to "gd" before the quality change started working. I wonder why it didn't work with "gd2"
$config['image_library'] = 'gd';
$config['quality'] = 40;
I found this would not work for me using the GD or GD2 library.
In order for the "quality" to be affected - I needed to use the "ImageMagick" Library.
As stated in the documentation - if you use either the "ImageMagick" or the "NetPBM" library - "you must supply the path": https://codeigniter.com/userguide3/libraries/image_lib.html
On my GoDaddy server the path was "/usr/bin"
$config['source_image'] = $source_image;
$config['library_path'] = '/usr/bin';
$config['image_library'] = 'ImageMagick';
$config['maintain_ratio'] = TRUE;
$config['quality'] = "20%"; // Maintained the aspect ratio and dimensions but reduced the file size by about 60%
$this->image_lib->initialize($config);
if(!$this->image_lib->resize()){
echo "QUCKVIEW Re-sizing - ";
echo $this->image_lib->display_errors();
echo "Image Resize for Grooming Quickview Failed! Contact System Administrator.";
die();
}

how can i provide image library path for imagemagick

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.

Resize and rotate image - Codeigniter

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'; //

Multiple resizing in CodeIgniter

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;

Categories