create_thumbnails.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Tidypics Thumbnail Creation Test
  4. *
  5. * Called through ajax, but registered as an Elgg action.
  6. *
  7. */
  8. elgg_load_library('tidypics:resize');
  9. $guid = get_input('guid');
  10. $image = get_entity($guid);
  11. if (!$image || !($image instanceof TidypicsImage)) {
  12. register_error(elgg_echo('tidypics:thumbnail_tool:unknown_image'));
  13. forward(REFERER);
  14. }
  15. $filename = $image->getFilename();
  16. $container_guid = $image->container_guid;
  17. if (!$filename || !$container_guid) {
  18. register_error(elgg_echo('tidypics:thumbnail_tool:invalid_image_info'));
  19. forward(REFERER);
  20. }
  21. $title = $image->getTitle();
  22. $prefix = "image/$container_guid/";
  23. $filestorename = substr($filename, strlen($prefix));
  24. $image_lib = elgg_get_plugin_setting('image_lib', 'tidypics');
  25. if (!$image_lib) {
  26. $image_lib = "GD";
  27. }
  28. // ImageMagick command line
  29. if ($image_lib == 'ImageMagick') {
  30. if (!tp_create_im_cmdline_thumbnails($image, $prefix, $filestorename)) {
  31. trigger_error('Tidypics warning: failed to create thumbnails - ImageMagick command line', E_USER_WARNING);
  32. register_error(elgg_echo('tidypics:thumbnail_tool:create_failed'));
  33. forward(REFERER);
  34. }
  35. // imagick PHP extension
  36. } else if ($image_lib == 'ImageMagickPHP') {
  37. if (!tp_create_imagick_thumbnails($image, $prefix, $filestorename)) {
  38. trigger_error('Tidypics warning: failed to create thumbnails - ImageMagick PHP', E_USER_WARNING);
  39. register_error(elgg_echo('tidypics:thumbnail_tool:create_failed'));
  40. forward(REFERER);
  41. }
  42. // gd
  43. } else {
  44. if (!tp_create_gd_thumbnails($image, $prefix, $filestorename)) {
  45. trigger_error('Tidypics warning: failed to create thumbnails - GD', E_USER_WARNING);
  46. register_error(elgg_echo('tidypics:thumbnail_tool:create_failed'));
  47. forward(REFERER);
  48. }
  49. }
  50. $url = elgg_normalize_url("photos/thumbnail/$guid/large");
  51. system_message(elgg_echo('tidypics:thumbnail_tool:created'));
  52. if (elgg_is_xhr()) {
  53. echo json_encode(array(
  54. 'guid' => $guid,
  55. 'title' => $title,
  56. 'thumbnail_src' => $url
  57. ));
  58. }
  59. forward(REFERER);