README.txt 9.3 KB

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