Zend_View-Helpers-TinySrc.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect3 id="zend.view.helpers.initial.tiny-src">
  4. <title>TinySrc Helper</title>
  5. <sect4 id="zend.view.helpers.initial.tiny-src.intro">
  6. <title>Overview</title>
  7. <para>
  8. <ulink url="http://tinysrc.net/">tinysrc.net</ulink> provides an API for automatic scaling
  9. and image format conversion for use with mobile devices. The API is quite simple: you
  10. simply create a standard HTML image tag, but append your image URL to a URL on the
  11. tinysrc.net domain:
  12. </para>
  13. <programlisting language="html"><![CDATA[
  14. <img src="http://i.tinysrc.net/http://yourdomain.com/images/foo.jpg" />
  15. ]]></programlisting>
  16. <para>
  17. Their service then sizes the image appropriately for the device requesting it.
  18. </para>
  19. <para>
  20. You can control a number of aspects regarding image display, including:
  21. </para>
  22. <itemizedlist>
  23. <listitem>
  24. <para>
  25. <emphasis>Image dimensions</emphasis>. You may specify a width and optional
  26. height. These dimensions can be in absolute pixels, or use one of the adaptive
  27. mechanisms tinysrc.net offers. One is <emphasis>subtractive</emphasis>;
  28. prepending a dimension with a minus ("-") indicates that the image should fill
  29. the maximum physical dimensions, <emphasis>minus</emphasis> the value given in
  30. pixels. The other is <emphasis>percentage</emphasis> based; prepending a
  31. dimension with an "x" tells the service to size that dimension by that
  32. percentage -- e.g., "x20" indicates "20%".
  33. </para>
  34. </listitem>
  35. <listitem>
  36. <para>
  37. <emphasis>Image format</emphasis>. By default, tinysrc.net autodiscovers the
  38. format. Internally, it supports only <acronym>JPEG</acronym> or
  39. <acronym>PNG</acronym>, and autoconverts <acronym>GIF</acronym> to
  40. <acronym>PNG</acronym>. You can specifically request that it should convert an
  41. image to either <acronym>PNG</acronym> or <acronym>JPEG</acronym>, however.
  42. </para>
  43. </listitem>
  44. </itemizedlist>
  45. <para>
  46. The <classname>TinySrc</classname> view helper provides functionality around the
  47. tinysrc.net API, and gives you the ability to:
  48. </para>
  49. <itemizedlist>
  50. <listitem>
  51. <para>
  52. selectively enable or disable whether it returns just the tinysrc.net URL or a
  53. fully-populated HTML <acronym>img</acronym> tag (enabled by default);
  54. </para>
  55. </listitem>
  56. <listitem>
  57. <para>
  58. specify default values for image format as well as width and height;
  59. </para>
  60. </listitem>
  61. <listitem>
  62. <para>
  63. specify a default value for the base URL used (uses the <link
  64. linkend="zend.view.helpers.initial.baseurl">BaseUrl</link> and <link
  65. linkend="zend.view.helpers.initial.serverurl">ServerUrl</link> view helpers
  66. by default);
  67. </para>
  68. </listitem>
  69. <listitem>
  70. <para>
  71. override the default options on a per-image basis, via passed in options.
  72. </para>
  73. </listitem>
  74. </itemizedlist>
  75. </sect4>
  76. <sect4 id="zend.view.helpers.initial.tiny-src.quick-start">
  77. <title>Quick Start</title>
  78. <para>
  79. The most basic usage is simply to pass the path to an image, relative to your document
  80. root or base URL, to create the appropriate image tag:
  81. </para>
  82. <programlisting language="php"><![CDATA[
  83. <?php echo $this->tinySrc('/images/foo.png'); ?>
  84. ]]></programlisting>
  85. <para>
  86. You may specify default values for the base URL, conversion format, dimensions, and
  87. whether or not to create an <acronym>img</acronym> tag by default:
  88. </para>
  89. <programlisting language="php"><![CDATA[
  90. <?php $this->tinySrc()
  91. ->setBaseUrl('http://example.com/foo/')
  92. ->setCreateTag(false) // disable tag creation
  93. ->setDefaultFormat('png') // convert images to PNG
  94. ->setDefaultDimensions('-5', 'x20'); // width should be 5 less than screen width;
  95. // height should be 20% of total screen height
  96. ?>
  97. ]]></programlisting>
  98. <para>
  99. Finally, you can also pass in values as an array of options, passed as the second
  100. parameter:
  101. </para>
  102. <programlisting language="php"><![CDATA[
  103. <?php echo $this->tinySrc('/images/foo.png', array(
  104. 'format' => 'jpg', // convert to JPEG
  105. 'width' => 'x50', // 1/2 screen width
  106. ); ?>
  107. ]]></programlisting>
  108. </sect4>
  109. <sect4 id="zend.view.helpers.initial.tiny-src.options">
  110. <title>Configuration Options</title>
  111. <variablelist>
  112. <title>TinySrc Helper Options</title>
  113. <para>
  114. The following options may be passed to the <varname>$options</varname> (second)
  115. argument of the helper.
  116. </para>
  117. <varlistentry>
  118. <term>base_url</term>
  119. <listitem>
  120. <para>
  121. The base URL, including scheme, host, and optionally port and/or path; this
  122. value will be prepended to the image path provided in the first argument. By
  123. default, this uses the <classname>BaseUrl</classname> and
  124. <classname>ServerUrl</classname> view helpers to determine the value.
  125. </para>
  126. </listitem>
  127. </varlistentry>
  128. <varlistentry>
  129. <term>create_tag</term>
  130. <listitem>
  131. <para>
  132. A boolean value indicating whether or not the helper should return an HTML
  133. <acronym>img</acronym> tag, or simply the tinysrc.net URL. By default, this
  134. flag is enabled.
  135. </para>
  136. </listitem>
  137. </varlistentry>
  138. <varlistentry>
  139. <term>format</term>
  140. <listitem>
  141. <para>
  142. Should be one of the values "png" or "jpeg". If specified, this value will
  143. be used to indicate the image conversion format. If not specified, the
  144. default format will be used, or the format will be auto-determined based on
  145. the image itself.
  146. </para>
  147. </listitem>
  148. </varlistentry>
  149. <varlistentry>
  150. <term>width</term>
  151. <listitem>
  152. <para>
  153. This should be either <constant>null</constant>, or an integer (optionally
  154. prefixed by "x" or "-"). If specified, this value will be used to determine
  155. the converted image width. If null, neither a width nor a height value will
  156. be used. If not specified, the default dimensions will be used.
  157. </para>
  158. </listitem>
  159. </varlistentry>
  160. <varlistentry>
  161. <term>height</term>
  162. <listitem>
  163. <para>
  164. This should be either <constant>null</constant>, or an integer (optionally
  165. prefixed by "x" or "-"). If specified, this value will be used to determine
  166. the converted image height. If null, no height value will be used. If not
  167. specified, the default height will be used.
  168. </para>
  169. </listitem>
  170. </varlistentry>
  171. </variablelist>
  172. <para>
  173. Any other options provided will be used as attributes to the HTML <acronym>img</acronym>
  174. tag (if created).
  175. </para>
  176. </sect4>
  177. <sect4 id="zend.view.helpers.initial.tiny-src.methods">
  178. <title>Available Methods</title>
  179. <variablelist>
  180. <varlistentry id="zend.view.helpers.initial.tiny-src.methods.tiny-src">
  181. <term>
  182. <methodsynopsis>
  183. <methodname>tinySrc</methodname>
  184. <methodparam>
  185. <funcparams>$image = null, array $options = array()</funcparams>
  186. </methodparam>
  187. </methodsynopsis>
  188. </term>
  189. <listitem>
  190. <para>
  191. Called with no arguments, returns the helper instance. This is useful for
  192. configuring the helper.
  193. </para>
  194. <para>
  195. If the <varname>$image</varname> argument is provided, it will either create and
  196. return the tinysrc.net URL for the image, or an image tag containing that URL as
  197. the source, depending on the status of the "create tag" flag (either the default
  198. value, or the value passed via <varname>$options</varname>).
  199. </para>
  200. <para>
  201. See the <link linkend="zend.view.helpers.initial.tiny-src.options">configuration
  202. section</link> for details on the <varname>$options</varname> array.
  203. </para>
  204. </listitem>
  205. </varlistentry>
  206. <varlistentry id="zend.view.helpers.initial.tiny-src.methods.set-base-url">
  207. <term>
  208. <methodsynopsis>
  209. <methodname>setBaseUrl</methodname>
  210. <methodparam>
  211. <funcparams>$url</funcparams>
  212. </methodparam>
  213. </methodsynopsis>
  214. </term>
  215. <listitem>
  216. <para>
  217. Use this method to manually specify the base URL to prepend to the
  218. <varname>$image</varname> argument of the <methodname>tinySrc()</methodname>
  219. method.
  220. </para>
  221. </listitem>
  222. </varlistentry>
  223. <varlistentry id="zend.view.helpers.initial.tiny-src.methods.get-base-url">
  224. <term>
  225. <methodsynopsis>
  226. <methodname>getBaseUrl</methodname>
  227. </methodsynopsis>
  228. </term>
  229. <listitem>
  230. <para>
  231. Retrieve the base URL for prepending to image URLs. By default, autodiscovers
  232. this from the <classname>BaseUrl</classname> and
  233. <classname>ServerUrl</classname> view helpers.
  234. </para>
  235. </listitem>
  236. </varlistentry>
  237. <varlistentry id="zend.view.helpers.initial.tiny-src.methods.set-default-format">
  238. <term>
  239. <methodsynopsis>
  240. <methodname>setDefaultFormat</methodname>
  241. <methodparam>
  242. <funcparams>$format = null</funcparams>
  243. </methodparam>
  244. </methodsynopsis>
  245. </term>
  246. <listitem>
  247. <para>
  248. Specifiy the default image conversion format. If none provided, the value is
  249. cleared. Otherwise, expects either "png" or "jpeg".
  250. </para>
  251. </listitem>
  252. </varlistentry>
  253. <varlistentry id="zend.view.helpers.initial.tiny-src.methods.set-default-dimensions">
  254. <term>
  255. <methodsynopsis>
  256. <methodname>setDefaultDimensions</methodname>
  257. <methodparam>
  258. <funcparams>$width = null, $height = null</funcparams>
  259. </methodparam>
  260. </methodsynopsis>
  261. </term>
  262. <listitem>
  263. <para>
  264. Set the default dimensions for image conversion. If no <varname>$width</varname>
  265. is specified, an empty value is provided for all dimensions (setting the height
  266. requires a width as well). Passing no value for the height will set only a
  267. width. Dimensions should be specified as either pixel dimensions, or:
  268. </para>
  269. <itemizedlist>
  270. <listitem>
  271. <para>
  272. A pixel value, preceded by a "-" sign. This will indicate the width
  273. should take the entire screen size, minus the number of pixels
  274. specified.
  275. </para>
  276. </listitem>
  277. <listitem>
  278. <para>
  279. A percentage of the total screen dimensions, expressed as "x" followed
  280. by the percentage: "x20" is equivalent to 20%.
  281. </para>
  282. </listitem>
  283. </itemizedlist>
  284. </listitem>
  285. </varlistentry>
  286. <varlistentry id="zend.view.helpers.initial.tiny-src.methods.set-create-tag">
  287. <term>
  288. <methodsynopsis>
  289. <methodname>setCreateTag</methodname>
  290. <methodparam>
  291. <funcparams>$flag</funcparams>
  292. </methodparam>
  293. </methodsynopsis>
  294. </term>
  295. <listitem>
  296. <para>
  297. Indicate whether the <methodname>tinySrc()</methodname> method should create an
  298. HTML image tag. If boolean <constant>false</constant>, only a tinysrc.net URL
  299. will be returned.
  300. </para>
  301. </listitem>
  302. </varlistentry>
  303. <varlistentry id="zend.view.helpers.initial.tiny-src.methods.create-tag">
  304. <term>
  305. <methodsynopsis>
  306. <methodname>createTag</methodname>
  307. </methodsynopsis>
  308. </term>
  309. <listitem>
  310. <para>
  311. Returns the status of the "create tag" flag.
  312. </para>
  313. </listitem>
  314. </varlistentry>
  315. </variablelist>
  316. </sect4>
  317. <sect4 id="zend.view.helpers.initial.tiny-src.examples">
  318. <title>Examples</title>
  319. <example id="zend.view.helpers.initial.tiny-src.examples.url">
  320. <title>Returning only a tinysrc.net URL</title>
  321. <para>
  322. You may want to return only a tinysrc.net URL. To do this, you have two options:
  323. make this the default behavior, or specify in your <varname>$options</varname> not
  324. to create a tag.
  325. </para>
  326. <programlisting language="php"><![CDATA[
  327. // Specifying default behavior:
  328. $this->tinySrc()->setCreateTag(false);
  329. echo $this->tinySrc('image.jpg');
  330. // Per-image:
  331. echo $this->tinySrc('image.jpg', array('create_tag' => false));
  332. ]]></programlisting>
  333. </example>
  334. </sect4>
  335. </sect3>