Guest User

Untitled

a guest
Jun 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. private function crop_image($width, $height, $path, $new_path = false)
  2. {
  3. $this->load->library('image_lib');
  4. $this->image_lib->clear();
  5.  
  6. $config['image_library'] = 'gd2';
  7. $config['source_image'] = $path;
  8. if ( $new_path ) $config['new_image'] = $new_path;
  9.  
  10. if ($width>$height) {
  11. $config['width'] = round(($width/$height) * 135);
  12. $config['height'] = 135;
  13. }
  14. else {
  15. $config['width'] = 135;
  16. $config['height'] = round(($height/$width) * 135);
  17. }
  18.  
  19. $new_width=$config['width'];
  20. $new_height=$config['height'];
  21.  
  22.  
  23. $config['maintain_ratio'] = TRUE;
  24. $config['quality'] = '95%';
  25.  
  26. $this->image_lib->initialize($config);
  27. $this->image_lib->resize();
  28.  
  29. $config['image_library'] = 'gd2';
  30. $config['source_image'] = $new_path;
  31. if ( $new_path ) $config['new_image'] = $new_path;
  32. $config['width'] = 135;
  33. $config['height'] = 135;
  34. $config['maintain_ratio'] = FALSE;
  35. $config['quality'] = '95%';
  36.  
  37. if ($new_width>$new_height) {
  38. $config['x_axis'] = round((135-$new_width) / 2);
  39. $config['y_axis'] = 0;
  40. }
  41. else {
  42. $config['x_axis'] = 0;
  43. $config['y_axis'] = round((135-$new_height) / 2);
  44. }
  45.  
  46. $this->image_lib->initialize($config);
  47.  
  48. return $this->image_lib->crop();
  49.  
  50. }
Add Comment
Please, Sign In to add comment