README.txt 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. README
  2. ------
  3. README for the Image effect text module.
  4. Author Erwin Derksen (fietserwin: http://drupal.org/user/750928)
  5. Dependencies
  6. ------------
  7. Hard dependencies:
  8. - Imagecache actions.
  9. - Image (Drupal core).
  10. Soft dependencies/recommended modules:
  11. - Imagemagick (preferred toolkit).
  12. - PHP filter (Drupal core).
  13. Toolkit
  14. -------
  15. Personally, I prefer the imagemagick toolkit:
  16. - It is better in anti-aliasing, try to rotate an image using both toolkits and
  17. you will see what I mean.
  18. - It does not execute in the PHP memory space, so is not restricted by the
  19. memory_limit PHP setting.
  20. - The GD toolkit will, at least on my Windows configuration, keep the font file
  21. open after a text operation, so you cannot delete, move or rename it anymore.
  22. - This module does a better job with Imagemagick (see below).
  23. Installing
  24. ----------
  25. As usual. After enabling the module you can add texts to images. This image
  26. effect works with both the GD and imagemagick toolkit, though results differ
  27. depending on the tookit you use.
  28. More information about the effect data options
  29. ----------------------------------------------
  30. Font
  31. ----
  32. You have to supply the font file to use. The font type supported depend on the
  33. toolkit in use, but at least ttf files will always work. This option accepts
  34. either:
  35. 1 of the (enabled) scheme's:
  36. - public://
  37. - private:// Preferred for site specific masks, overlay's, etc, that do not need
  38. to be shared publicly.
  39. - module://{module_name}/{resource-name} Introduced by the imagecache_actions
  40. module and preferred for module provided resources, like the button overlay
  41. of the Video Embed Field Overlay module
  42. (http://drupal.org/project/video_embed_field_overlay).
  43. - temporary:// Unlikely to be useful, but supported anyway as all schemes are
  44. supported.
  45. or a relative (to the current directory, probably Drupal root) or absolute path.
  46. Text position
  47. -------------
  48. The text position defines the point in the image where you want to place (align)
  49. your text. It starts at the top left corner of the image with postion 0,0 and
  50. the positive directions are to the right and down.
  51. The definition of the vertical position differs per toolkit. For GD it is the
  52. position of the font baseline, while for Imagemagick it is the bottom of the
  53. bounding box, i.e the descender or beard line in typography terminology.
  54. Text alignment
  55. --------------
  56. You can align your text with regard to the text position. Possible horizontal
  57. alignments are left (default), center and right. Vertical alignments are top,
  58. center and bottom (default).
  59. Note: Given
  60. - the way that GD uses the vertical text position (as baseline),
  61. - and the way this module implements (vertical) alignment (translating the
  62. (vertical) position using the calculated bounding box),
  63. vertical alignment with the GD toolkit is a bit off. You will have to compensate
  64. for this yourself.
  65. Rotation
  66. --------
  67. The text can be rotated before being overlaid on the image. The vlaue is in
  68. degrees, so 90 degrees is straight down. Positive values are rotated clockwise,
  69. negative values counter clockwise.
  70. In Imagemagick the text is rotated around the text position. Thus centered text
  71. is rotated around its own center. GD, on the other hand, always rotates around
  72. the left bottom (baseline) position, regardless the text alignment. Using
  73. rotation with a non default alignment (left bottom) will give surprising
  74. results.
  75. Text source
  76. -----------
  77. Note: this module is not build to handle multi line texts. Not when the text
  78. contains new lines and/or carriage returns, and not to split a given text over
  79. multiple lines given an available width. Using "\n" in GD seems to work though.
  80. The text to place on the image may come from different sources:
  81. - Static: the text to place on the image is static and is defined in the image
  82. effect data. Use this e.g. for a fixed copyright notice.
  83. - PHP: the text to place on the iamge comes from a piece of PHP code that should
  84. return the text to place on the image. Only users with the 'use PHP for
  85. settings' permission are allowed to use this source. This permission and the
  86. evaluation of the PHP code come from the PHP filter module which is part of
  87. Drupal core and thus needs to be enabled, also during image generation.
  88. - To alleviate the need to enable the PHP filter module, 2 commonly used sources
  89. for dynamic texts are directly available without any coding, namely the alt
  90. and title properties of the image field linked to the image at hand. Note that
  91. multiple image fields, possibly in different languages, may be referring to
  92. the image that is being processed. This module will take the first image field
  93. it finds to extract the alt and title. If the field in itself is multi
  94. lingual, thus not a synced field, the current language will be taken, which is
  95. the language of the user that happens to request this styled image first.
  96. PHP snippets to determine the text
  97. ----------------------------------
  98. Given the correct permission, you can write your own PHP snippet to compute the
  99. text to display. To ease this task, this module makes some information regarding
  100. the image being processed available in 2 variables: $image and $image_context.
  101. These variables are readily available in your snippet.
  102. $image is an associative array containing:
  103. - source: string, the source of the image, e.g. public://photo.jpg
  104. - info: array, example data:
  105. - width (int) 180
  106. - height (int) 180
  107. - extension (string) png
  108. - mime_type (string) image/png
  109. - file_size (int) 4417
  110. - toolkit: string, imagemagick or GD
  111. $image_context is an associative array containing:
  112. - effect_data: array, the data of this image effect, example data for the text
  113. effect:
  114. - size (string) 12
  115. - xpos (string) center
  116. - ypos (string) center
  117. - halign (string) left
  118. - valign (string) bottom
  119. - RGB Array [1]
  120. - HEX (string) 000000
  121. - alpha (string) 100
  122. - angle (string) 0
  123. - fontfile (string:10) lhandw.ttf
  124. - text_source (string) text
  125. - text (string) Hello World!
  126. - php (string) return 'Hello World!'
  127. - managed_file: object|null. A managed file object containing these properties:
  128. - fid (string) 2
  129. - uid (string) 1
  130. - filename (string) photo.jpg
  131. - uri (string) public://photo.jpg
  132. - filemime (string) image/jpeg
  133. - filesize (string) 445751
  134. - status (string) 1
  135. - timestamp (string) 1327525851
  136. - metatags Array [0]
  137. - rdf_mapping Array [0]
  138. - referring_entities: array|null. A nested array with (fully loaded) entities
  139. referring to the current image. The 1st level of entries is keyed by the field
  140. name, the 2nd by entity type, and the 3rd by entity id. Example data:
  141. - field_photo Array [1]
  142. - node Array [1]
  143. - 12 Object of: stdClass
  144. - nid (string) 12
  145. - vid (string) 12
  146. - type (string) page
  147. - author ...
  148. - timestamp ...
  149. - ...
  150. - entity: object|null, the 1st entity in referring_entities. This is for easy
  151. access to the referring entity if it may be assumed that only 1 entity is
  152. referring to the current image.
  153. - image_field: array|null, the 1st image field in entity that is referring to
  154. the current image. This is for easy access to the image field data if it may
  155. be assumed that only 1 image field is referring to the current image. Example
  156. data:
  157. - fid (int) 2
  158. - alt (string) ...
  159. - title (string) ...
  160. - ...
  161. Of course there are many other possible useful globals. Think of:
  162. - base_url
  163. - base_path
  164. - base_root
  165. - is_https
  166. - user
  167. - language
  168. and of course $_SERVER and $_GET.
  169. Using these information you can access entity data as follows:
  170. Specific case (1 entity, of known entity_type, referring to the image):
  171. <?php
  172. $entity_type = 'node';
  173. $field_name = 'my_field';
  174. $entity = $image_context['entity'];
  175. $field = field_get_items($entity_type, $entity, $field_name);
  176. ?>
  177. Or the more general case (not knowing the referring type, or multiple entities
  178. that may be referring to the image):
  179. <?php
  180. $referring_entities = $image_context['referring_entities'];
  181. foreach ($referring_entities as $field_name => $field_referring_entities) {
  182. foreach ($field_referring_entities as $entity_type => $entities) {
  183. foreach ($entities as $entity_id => $entity) {
  184. $field = field_get_items($entity_type, $entity, $field_name);
  185. }
  186. }
  187. }
  188. ?>
  189. TODO
  190. ----
  191. - Vertical alignment: add baseline as vertical alignment and make both toolkits
  192. behave the same for any given vertical alignment.
  193. - Rotation and alignment. Imagemagick seems to be more correct. Can GD made to
  194. do the same?
  195. - Language and alt/title: what if the first user to pass by and that generates
  196. the image is in a language that has no alt/title?
  197. - Newlines: seem to work in GD, not in Imagemagick.
  198. To quote http://www.imagemagick.org/Usage/text/#draw:
  199. As of IM version 6.2.4, the "-draw text" operation no longer understands the use
  200. of '\n' as meaning newline, or the use of percent '%' image information escapes.
  201. (See Drawing a Percent Bug). These abilities, and problems, however remain
  202. available in the new IM v6 operator "-annotate". See the Annotate Text Drawing
  203. Operator below.