image_effects_text.module 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * @file Provide text manipulation effects for image styles.
  4. *
  5. * Ported by dman
  6. * from https://drupal.org/node/264862#comment-865490 by patrickharris
  7. *
  8. * Ported to D7 by fietserwin
  9. * from imagecache_textactions 6.x-1.8.
  10. * - The module has been renamed to follow D7 terminology:
  11. * * imagecache -> image
  12. * * action(s) -> effect(s)
  13. * resulting in image_effects_text.
  14. * - The .module file is kept as small as possible. The real work is done in the
  15. * .inc file.
  16. * - Function and parameter naming has been changed to match the image effects
  17. * in the core image module.
  18. */
  19. /**
  20. * Implements hook_image_effect_info().
  21. *
  22. * Defines information about the supported effects.
  23. */
  24. function image_effects_text_image_effect_info() {
  25. $effects = array();
  26. $effects['image_effects_text'] = array(
  27. 'label' => t('Text'),
  28. 'help' => t('Add static or dynamic (coded) text to an image.'),
  29. 'dimensions passthrough' => TRUE,
  30. 'effect callback' => 'image_effects_text_effect',
  31. 'form callback' => 'image_effects_text_form',
  32. 'summary theme' => 'image_effects_text_summary',
  33. );
  34. return $effects;
  35. }
  36. /**
  37. * Implements hook_help().
  38. */
  39. function image_effects_text_help($path, $arg) {
  40. if ($path === 'admin/advanced_help' && count($arg) >= 3 && $arg[2] === 'image_effects_text'
  41. || $path === 'admin/help/image_effects_text') {
  42. module_load_include('inc', 'image_effects_text', 'image_effects_text');
  43. return image_effects_text_help_inc($path, $arg);
  44. }
  45. else if ($path === 'admin/help#image_effects_text') {
  46. // This path just checks if there is (non-empty) help, so it can place a
  47. // link to it.
  48. return ' ';
  49. }
  50. return '';
  51. }
  52. /**
  53. * Implements hook_theme().
  54. *
  55. * Registers theme functions for the effect summaries.
  56. */
  57. function image_effects_text_theme() {
  58. return array(
  59. 'image_effects_text_summary' => array(
  60. 'variables' => array('data' => NULL),
  61. 'file' => 'image_effects_text.inc'
  62. ),
  63. );
  64. }
  65. /**
  66. * Implements hook_exit().
  67. *
  68. * For imagemagick we place the text in a temporary file as this prevents
  69. * problems with non-ASCII characters. This hook deletes files created during
  70. * execution of the text effect. As a style may contain multiple text effects,
  71. * there may be multiple files to delete.
  72. *
  73. * To keep track of temporary files created by this effect, the image effect
  74. * function itself also calls this hook, but passes the filename as a parameter.
  75. *
  76. * @param string|null $destination
  77. */
  78. function image_effects_text_exit($destination = NULL) {
  79. static $tmp_file_names = array();
  80. if (isset($destination)) {
  81. if (substr($destination, 0 , strlen('temporary://')) === 'temporary://') {
  82. // Called by the effect function. Add to our static list of files ot delete.
  83. $tmp_file_names[] = $destination;
  84. }
  85. }
  86. else {
  87. // Normal invocation as Drupal hook: delete any files we have collected.
  88. foreach ($tmp_file_names as $tmp_file_name) {
  89. unlink($tmp_file_name);
  90. }
  91. }
  92. }
  93. /**
  94. * Builds the form structure for the overlay text image effect.
  95. */
  96. function image_effects_text_form($data) {
  97. module_load_include('inc', 'image_effects_text', 'image_effects_text');
  98. return image_effects_text_form_inc($data);
  99. }
  100. /**
  101. * Callback to perform the image effect on the given image.
  102. */
  103. function image_effects_text_effect($image, $data) {
  104. module_load_include('inc', 'image_effects_text', 'image_effects_text');
  105. return image_effects_text_effect_inc($image, $data);
  106. }