createNewThumb

The NextCellent Gallery createNewThumb function.

Description

createNewThumb(); 

Usage

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

Defined (1)

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

/admin/ajax.php  
  1. function createNewThumb() { 
  2.  
  3. global $ngg; 
  4.  
  5. // check for correct capability 
  6. if ( !is_user_logged_in() ) 
  7. die('-1'); 
  8.  
  9. // check for correct NextGEN capability 
  10. if ( !current_user_can('NextGEN Manage gallery') ) 
  11. die('-1'); 
  12.  
  13. include_once( nggGallery::graphic_library() ); 
  14.  
  15. $id = (int) $_POST['id']; 
  16. $picture = nggdb::find_image( $id ); 
  17.  
  18. $x = round( $_POST['x'] * $_POST['rr'], 0); 
  19. $y = round( $_POST['y'] * $_POST['rr'], 0); 
  20. $w = round( $_POST['w'] * $_POST['rr'], 0); 
  21. $h = round( $_POST['h'] * $_POST['rr'], 0); 
  22.  
  23. $thumb = new ngg_Thumbnail($picture->imagePath, TRUE); 
  24.  
  25. $thumb->crop($x, $y, $w, $h); 
  26.  
  27. // Note : the routine is a bit different to create_thumbnail(), due to rounding it's resized in the other way 
  28. if ($ngg->options['thumbfix']) { 
  29. // check for portrait format 
  30. if ($thumb->currentDimensions['height'] > $thumb->currentDimensions['width']) { 
  31. // first resize to the wanted height, here changed to create_thumbnail() 
  32. $thumb->resize(0, $ngg->options['thumbheight']); 
  33. // get optimal y startpos 
  34. $ypos = ($thumb->currentDimensions['height'] - $ngg->options['thumbheight']) / 2; 
  35. $thumb->crop(0, $ypos, $ngg->options['thumbwidth'], $ngg->options['thumbheight']); 
  36. } else { 
  37. // first resize to the wanted width, here changed to create_thumbnail() 
  38. $thumb->resize($ngg->options['thumbwidth'], 0); 
  39. // 
  40. // get optimal x startpos 
  41. $xpos = ($thumb->currentDimensions['width'] - $ngg->options['thumbwidth']) / 2; 
  42. $thumb->crop($xpos, 0, $ngg->options['thumbwidth'], $ngg->options['thumbheight']); 
  43. //this create a thumbnail but keep ratio settings 
  44. } else { 
  45. $thumb->resize($ngg->options['thumbwidth'], $ngg->options['thumbheight']); 
  46.  
  47. if ( $thumb->save($picture->thumbPath, 100)) { 
  48.  
  49. //read the new sizes 
  50. $new_size = @getimagesize ( $picture->thumbPath ); 
  51. $size['width'] = $new_size[0]; 
  52. $size['height'] = $new_size[1]; 
  53.  
  54. // add them to the database 
  55. nggdb::update_image_meta($picture->pid, array( 'thumbnail' => $size) ); 
  56.  
  57. echo "OK"; 
  58. } else { 
  59. header('HTTP/1.1 500 Internal Server Error'); 
  60. echo "KO"; 
  61.  
  62. exit(); 
  63.