README.txt 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. README
  2. ------
  3. README for the custom actions effect module.
  4. Dependencies
  5. ------------
  6. Hard dependencies:
  7. - Imagecache actions.
  8. - Image (Drupal core).
  9. Soft dependencies/recommended modules:
  10. - Imagemagick (preferred toolkit).
  11. - PHP filter (Drupal core).
  12. Toolkit
  13. -------
  14. Personally, I prefer the imagemagick toolkit:
  15. - It is better in anti-aliasing, try to rotate an image using both toolkits and
  16. you will see what I mean.
  17. - It does not execute in the PHP memory space, so is not restricted by the
  18. memory_limit PHP setting.
  19. - The GD toolkit will, at least on my Windows configuration, keep the font file
  20. open after a text operation, so you cannot delete, move or rename it anymore.
  21. - This module does a better job with Imagemagick (see below).
  22. Installing
  23. ----------
  24. As usual. After enabling the module you can add custom actions to images.
  25. Custom action PHP snippets
  26. --------------------------
  27. Given the correct permission, the custom action effect allows you to write your
  28. own PHP snippet that does the requested processing on the image. How it can do
  29. so, depends on the toolkit.
  30. For all toolkits, the snippet should return true to indicate success and false
  31. to indicate failure.
  32. GD
  33. --
  34. The GD image resource is available in $image->resource. You can call the GD
  35. functions on this resource. This effect will query the width and height after
  36. your processing, so you don't have to change that yourself.
  37. Imagemagick
  38. -----------
  39. All real image processing is done at the end, if all effects have added their
  40. command line arguments to the $image->ops array. So your custom action should
  41. add the imagemagick commands and its parameters by adding new string entries to
  42. the end of that array.
  43. If your commands change the width or height of the resulting image, you should
  44. record so by changing $image->info['width'] and/or $image->info['height'].
  45. General
  46. -------
  47. To ease your task, this effect makes some information regarding the image being
  48. processed available in 2 variables: $image and $image_context. These variables
  49. are readily available in your snippet.
  50. $image is an associative array containing:
  51. - source: string, the source of the image, e.g. public://photo.jpg
  52. - info: array, example data:
  53. - width (int) 180
  54. - height (int) 180
  55. - extension (string) png
  56. - mime_type (string) image/png
  57. - file_size (int) 4417
  58. - toolkit: string, imagemagick or GD
  59. $image_context is an associative array containing:
  60. - effect_data: array, the data of this image effect, example data for the custom
  61. action effect:
  62. - php (string)
  63. - managed_file: object|null. A managed file object containing these properties:
  64. - fid (string) 2
  65. - uid (string) 1
  66. - filename (string) photo.jpg
  67. - uri (string) public://photo.jpg
  68. - filemime (string) image/jpeg
  69. - filesize (string) 445751
  70. - status (string) 1
  71. - timestamp (string) 1327525851
  72. - metatags Array [0]
  73. - rdf_mapping Array [0]
  74. - referring_entities: array|null. A nested array with (fully loaded) entities
  75. referring to the current image. The 1st level of entries is keyed by the field
  76. name, the 2nd by entity type, and the 3rd by entity id. Example data:
  77. - field_photo Array [1]
  78. - node Array [1]
  79. - 12 Object of: stdClass
  80. - nid (string) 12
  81. - vid (string) 12
  82. - type (string) page
  83. - author ...
  84. - timestamp ...
  85. - ...
  86. - entity: object|null, the 1st entity in referring_entities. This is for easy
  87. access to the referring entity if it may be assumed that only 1 entity is
  88. referring to the current image.
  89. - image_field: array|null, the 1st image field in entity that is referring to
  90. the current image. This is for easy access to the image field data if it may
  91. be assumed that only 1 image field is referring to the current image. Example
  92. data:
  93. - fid (int) 2
  94. - alt (string) ...
  95. - title (string) ...
  96. - ...
  97. Of course there are many other possible useful globals. Think of:
  98. - base_url
  99. - base_path
  100. - base_root
  101. - is_https
  102. - user
  103. - language
  104. and of course $_SERVER and $_GET.
  105. Using these information you can access entity data as follows:
  106. Specific case (1 entity, of known entity_type, referring to the image):
  107. <?php
  108. $entity_type = 'node';
  109. $field_name = 'my_field';
  110. $entity = $image_context['entity'];
  111. $field = field_get_items($entity_type, $entity, $field_name);
  112. ?>
  113. Or the more general case (not knowing the referring type, or multiple entities
  114. that may be referring to the image):
  115. <?php
  116. $referring_entities = $image_context['referring_entities'];
  117. foreach ($referring_entities as $field_name => $field_referring_entities) {
  118. foreach ($field_referring_entities as $entity_type => $entities) {
  119. foreach ($entities as $entity_id => $entity) {
  120. $field = field_get_items($entity_type, $entity, $field_name);
  121. }
  122. }
  123. }
  124. ?>