Filed under: Code Igniter | Tags: CI image crop, ci multiple image resize, image manipulation, multiple image manipulation
This is really nightmare to sort out why loop operation get success only for first time. Say, with or without loop i want to resize two images in a single script. i write the resize code but when i execute i found only first image is resized but not second one. WHY??????
after search and search, R&D, test and test finally able to find out the reason. a single line of extra code resolve my issue. and now i am able to resize 100 images inside a loop or write code multiple times to manipulate multiple images. This is the extra line of code:
$this->image_lib->initialize($config);
and here i am croping 100 of images using CI
foreach (glob(“./newspaper-jobs/prothom-alo/2009-05-22/*.jpg”) as $filename)
{
list($width, $height, $type, $attr) = getimagesize($filename);
//here are some logic. set it as you need or discard this portion but adjust variables by yourself.
$crop_x_axis = 0;
if($width<$height)
{
$crop_height_width = $width;
}
else // $width>$height
{
$crop_height_width = $height;
$crop_x_axis = ($width-$height)/2;
}
unset($config);
//Crop an image(Height = Width) Depend on current Height and Width of image
$config['image_library'] = ‘gd2′;
echo $config['source_image'] = ‘./source/image/location/’.basename($filename);
$config['new_image'] = ‘./destination/loc/’.basename($filename);
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = FALSE;
echo $config['width'] = $crop_height_width;
echo $config['height'] = $crop_height_width;
echo $config['x_axis'] = $crop_x_axis;
$config['y_axis'] = 0;
$this->load->library(‘image_lib’, $config);
$this->image_lib->initialize($config);
if ( ! $this->image_lib->crop())
{
echo $this->image_lib->display_errors();
}
$this->image_lib->clear();
}
Enjoy image resizing/croping/or whatever it is !!!
$config['image_library'] = ‘gd2′;
$config['source_image'] = ‘./source/img/loc/aminul.jpg’;
$config['new_image'] = ‘./dest/img/loc/new.jpg’;
$config['create_thumb'] = TRUE;
$config['width'] = ‘300′;
$config['height'] = ‘300′;
$config['x_axis'] = ‘600′;
$config['y_axis'] = ‘350′;
//$this->image_lib->initialize($config);
$this->load->library(‘image_lib’, $config);
if ( ! $this->image_lib->crop())
{
echo $this->image_lib->display_errors();
}
Enjoy Croping with CI
Filed under: Code Igniter | Tags: ci image resize, image manipulation, image resize
I found an interesting thing about CI file resize functionality. To resize an image we need to load image_lib library.
$this->load->library(‘image_lib’); //don’t use it
But if we load this library first and assign configuration variables later then it gives the following error:
Your server does not support the GD function required to process this type of image.\
instead first make ready your configuration variables and then load the library as
$config['image_library'] = ‘gd2′;
$config['source_image'] = ‘./existing/img/loc/aminul.jpg’;
$config['create_thumb'] = TRUE;
//$config['new_image'] = ‘./new/image/location/new_amin.jpg’; // you can assign your image name and location
$config['maintain_ratio'] = TRUE;
$config['width'] = 75;
$config['height'] = 50;
$this->load->library(‘image_lib’, $config);
if ( ! $this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}
now it should work fine without any error in CI.
what is .htaccess?
=> it’s a file located at your server use for control apache activities. usually we place .htaccess file in server root but it’s also possible to locate elsewhere. moreover, .htaccess file help us to rewrite apache behavior. in addition, you can rewrite some variables of php.ini form .htaccess file. regardless of php framework or coding style .htaccess is helpful for all.
have a look my previous tutorial which describe basics of .htaccess file in server and local host.
Well now some advance topics. you can rewriet php.ini upload maximum file size value using the following line of command in your .htaccess file
php_value upload_max_filesize “25M”
and test it from your php script by
echo ini_get("upload_max_filesize");
.htaccess ReWrite Rules(Short and Very Very useful)
http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html
Yes!!! Today is really special day for me. It’s orientation and first class in IICT at BUET. This year i get chance at BUET in MSc in ICT. It was my father’s dream i shall become a student of BUET. but i am such stupid who dont’ have enough marks in HSC and as a result was not eligible to apply for under graduate program. however, after couple of years i get eligibility to apply and it’s post graduate program. i sit in admission test and get chance. thanks to allah.
And finally from today our class starts. in our orientation i found it’s really really hard to pass. more tough then get admission. pray for me so that i can complete MSc from BUET.