new_thumbnail

Create a new thumbnail.

Description

new_thumbnail(); 

Usage

  1. if ( !function_exists( 'new_thumbnail' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'nextcellent-gallery/admin/ajax.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = new_thumbnail(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/admin/ajax.php  
  1. function new_thumbnail() { 
  2.  
  3. global $ngg; 
  4. $ngg_options = get_option(ngg_options); 
  5.  
  6. // check for correct capability 
  7. if ( !(is_user_logged_in() && current_user_can('NextGEN Manage gallery')) ) { 
  8. wp_die('-1'); 
  9.  
  10. include_once( nggGallery::graphic_library() ); 
  11.  
  12. $id = (int) $_POST['id']; 
  13. $picture = nggdb::find_image( $id ); 
  14.  
  15. $data = $_POST['newData']; 
  16.  
  17. $x = (int) $data['x']; 
  18. $y = (int) $data['y']; 
  19. $w = (int) $data['width']; 
  20. $h = (int) $data['height']; 
  21.  
  22. $thumb = new ngg_Thumbnail($picture->imagePath, TRUE); 
  23.  
  24. if($data['rotate'] == '90') { 
  25. $thumb->rotateImage('CW'); 
  26. } elseif ($data['rotate'] == '-90') { 
  27. $thumb->rotateImage('CCW'); 
  28.  
  29. $thumb->crop($x, $y, $w, $h); 
  30.  
  31. $differentSizes = false; 
  32. if(isset($ngg_options['thumbDifferentSize'])) { 
  33. $differentSizes = (bool) $ngg_options['thumbDifferentSize']; 
  34.  
  35. if(!$differentSizes) { 
  36. if($ngg_options['thumbfix']) { 
  37. $thumb->resizeFix((int) $ngg_options['thumbwidth'], (int) $ngg_options['thumbheight']); 
  38. } else { 
  39. $thumb->resize((int) $ngg_options['thumbwidth'], (int) $ngg_options['thumbheight']); 
  40.  
  41. if ( $thumb->save($picture->thumbPath, 100)) { 
  42.  
  43. //read the new sizes 
  44. $new_size = @getimagesize ( $picture->thumbPath ); 
  45. $size['width'] = $new_size[0]; 
  46. $size['height'] = $new_size[1]; 
  47.  
  48. // add them to the database 
  49. nggdb::update_image_meta($picture->pid, array( 'thumbnail' => $size) ); 
  50.  
  51. echo "OK"; 
  52. } else { 
  53. header('HTTP/1.1 500 Internal Server Error'); 
  54. echo "KO"; 
  55.  
  56. exit();