CodeIgniter Forums
Square images and centered thumbs with image_lib - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Square images and centered thumbs with image_lib (/showthread.php?tid=44209)



Square images and centered thumbs with image_lib - El Forum - 08-07-2011

[eluser]Unknown[/eluser]
Hi all i'm trying cropping then resizing images for create thumbs .... i don't think my lib crop() functions still working cause i see images only resized at 80x80 px but not cropped first Sad

no errors from echo $this->image_lib->display_errors() returns Sad

i would like to ... first (according to original $imgWidth and $imgHeight) crop them and make them squared , then resize them to a fixed thumb dimension (80x80px) .... but seems something wrong with cropping still not working maybe !? Sad


Code:
$this->load->library('image_lib');
                      if($imgWidth > $imgHeight){
                      $img['image_library'] = 'gd2';
                      $img['source_image'] = 'uploads/img/gallery/small/'.$photo;
                      $img['maintain_ratio'] = FALSE;
                      $img['x_axis'] = $imgWidth - $imgHeight;
                      $img['y_axis'] = $imgHeight;
                      $this->image_lib->initialize($img);
                      $this->image_lib->crop();

                      echo $this->image_lib->display_errors();
                      
                      }
                       if($imgWidth < $imgHeight){
                      $img['image_library'] = 'gd2';
                      $img['source_image'] = 'uploads/img/gallery/small/'.$photo;
                      $img['maintain_ratio'] = FALSE;
                      $img['x_axis'] = $imgWidth;
                      $img['y_axis'] = $imgHeight-$imgWidth;
                      $this->image_lib->initialize($img);
                      $this->image_lib->crop();

                      echo $this->image_lib->display_errors();
                      
                      }
                      $img['image_library'] = 'gd2';
                      $img['source_image'] = 'uploads/img/gallery/small/'.$photo;
                      $img['maintain_ratio'] = FALSE;
                      $img['width'] = 80;
                      $img['height'] = 80;
                      $this->image_lib->initialize($img);
                      $this->image_lib->resize();
                      echo $this->image_lib->display_errors();
check this code someone have any idea? Sad


Square images and centered thumbs with image_lib - El Forum - 08-08-2011

[eluser]Team Kulafihi[/eluser]
Here is a very well explained tutorial on file uploading and image manipulation. Hope will be of help. Codeigniter From Scratch