Zend_View-Helpers-TinySrc.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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> view helper
  65. by default);
  66. </para>
  67. </listitem>
  68. <listitem>
  69. <para>
  70. override the default options on a per-image basis, via passed in options.
  71. </para>
  72. </listitem>
  73. </itemizedlist>
  74. </sect4>
  75. <sect4 id="zend.view.helpers.initial.tiny-src.quick-start">
  76. <title>Quick Start</title>
  77. <para>
  78. The most basic usage is simply to pass the path to an image, relative to your document
  79. root or base URL, to create the appropriate image tag:
  80. </para>
  81. <programlisting language="php"><![CDATA[
  82. <?php echo $this->tinySrc('/images/foo.png'); ?>
  83. ]]></programlisting>
  84. <para>
  85. You may specify default values for the base URL, conversion format, dimensions, and
  86. whether or not to create an <acronym>img</acronym> tag by default:
  87. </para>
  88. <programlisting language="php"><![CDATA[
  89. <?php $this->tinySrc()
  90. ->setBaseUrl('http://example.com/foo/')
  91. ->setCreateTag(false) // disable tag creation
  92. ->setDefaultFormat('png') // convert images to PNG
  93. ->setDefaultDimensions('-5', 'x20'); // width should be 5 less than screen width;
  94. // height should be 20% of total screen height
  95. ?>
  96. ]]></programlisting>
  97. <para>
  98. Finally, you can also pass in values as an array of options, passed as the second
  99. parameter:
  100. </para>
  101. <programlisting language="php"><![CDATA[
  102. <?php echo $this->tinySrc('/images/foo.png', array(
  103. 'format' => 'jpg', // convert to JPEG
  104. 'width' => 'x50', // 1/2 screen width
  105. ); ?>
  106. ]]></programlisting>
  107. </sect4>
  108. <sect4 id="zend.view.helpers.initial.tiny-src.options">
  109. <title>Configuration Options</title>
  110. <variablelist>
  111. <title>TinySrc Helper Options</title>
  112. <para>
  113. The following options may be passed to the <varname>$options</varname> (second)
  114. argument of the helper.
  115. </para>
  116. <varlistentry>
  117. <term>base_url</term>
  118. <listitem>
  119. <para>
  120. The base URL, including scheme, host, and optionally port and/or path; this
  121. value will be prepended to the image path provided in the first argument. By
  122. default, this uses the <classname>BaseUrl</classname> and
  123. <classname>ServerUrl</classname> view helpers to determine the value.
  124. </para>
  125. </listitem>
  126. </varlistentry>
  127. <varlistentry>
  128. <term>create_tag</term>
  129. <listitem>
  130. <para>
  131. A boolean value indicating whether or not the helper should return an HTML
  132. <acronym>img</acronym> tag, or simply the tinysrc.net URL. By default, this
  133. flag is enabled.
  134. </para>
  135. </listitem>
  136. </varlistentry>
  137. <varlistentry>
  138. <term>format</term>
  139. <listitem>
  140. <para>
  141. Should be one of the values "png" or "jpeg". If specified, this value will
  142. be used to indicate the image conversion format. If not specified, the
  143. default format will be used, or the format will be auto-determined based on
  144. the image itself.
  145. </para>
  146. </listitem>
  147. </varlistentry>
  148. <varlistentry>
  149. <term>width</term>
  150. <listitem>
  151. <para>
  152. This should be either <constant>null</constant>, or an integer (optionally
  153. prefixed by "x" or "-"). If specified, this value will be used to determine
  154. the converted image width. If null, neither a width nor a height value will
  155. be used. If not specified, the default dimensions will be used.
  156. </para>
  157. </listitem>
  158. </varlistentry>
  159. <varlistentry>
  160. <term>height</term>
  161. <listitem>
  162. <para>
  163. This should be either <constant>null</constant>, or an integer (optionally
  164. prefixed by "x" or "-"). If specified, this value will be used to determine
  165. the converted image height. If null, no height value will be used. If not
  166. specified, the default height will be used.
  167. </para>
  168. </listitem>
  169. </varlistentry>
  170. </variablelist>
  171. <para>
  172. Any other options provided will be used as attributes to the HTML <acronym>img</acronym>
  173. tag (if created).
  174. </para>
  175. </sect4>
  176. <sect4 id="zend.view.helpers.initial.tiny-src.methods">
  177. <title>Available Methods</title>
  178. <variablelist>
  179. <varlistentry id="zend.view.helpers.initial.tiny-src.methods.tiny-src">
  180. <term>
  181. <methodsynopsis>
  182. <methodname>tinySrc</methodname>
  183. <methodparam>
  184. <funcparams>$image = null, array $options = array()</funcparams>
  185. </methodparam>
  186. </methodsynopsis>
  187. </term>
  188. <listitem>
  189. <para>
  190. Called with no arguments, returns the helper instance. This is useful for
  191. configuring the helper.
  192. </para>
  193. <para>
  194. If the <varname>$image</varname> argument is provided, it will either create and
  195. return the tinysrc.net URL for the image, or an image tag containing that URL as
  196. the source, depending on the status of the "create tag" flag (either the default
  197. value, or the value passed via <varname>$options</varname>).
  198. </para>
  199. <para>
  200. See the <link linkend="zend.view.helpers.initial.tiny-src.options">configuration
  201. section</link> for details on the <varname>$options</varname> array.
  202. </para>
  203. </listitem>
  204. </varlistentry>
  205. <varlistentry id="zend.view.helpers.initial.tiny-src.methods.set-base-url">
  206. <term>
  207. <methodsynopsis>
  208. <methodname>setBaseUrl</methodname>
  209. <methodparam>
  210. <funcparams>$url</funcparams>
  211. </methodparam>
  212. </methodsynopsis>
  213. </term>
  214. <listitem>
  215. <para>
  216. Use this method to manually specify the base URL to prepend to the
  217. <varname>$image</varname> argument of the <methodname>tinySrc()</methodname>
  218. method.
  219. </para>
  220. </listitem>
  221. </varlistentry>
  222. <varlistentry id="zend.view.helpers.initial.tiny-src.methods.get-base-url">
  223. <term>
  224. <methodsynopsis>
  225. <methodname>getBaseUrl</methodname>
  226. </methodsynopsis>
  227. </term>
  228. <listitem>
  229. <para>
  230. Retrieve the base URL for prepending to image URLs. By default, autodiscovers
  231. this from the <classname>BaseUrl</classname> and
  232. <classname>ServerUrl</classname> view helpers.
  233. </para>
  234. </listitem>
  235. </varlistentry>
  236. <varlistentry id="zend.view.helpers.initial.tiny-src.methods.set-default-format">
  237. <term>
  238. <methodsynopsis>
  239. <methodname>setDefaultFormat</methodname>
  240. <methodparam>
  241. <funcparams>$format = null</funcparams>
  242. </methodparam>
  243. </methodsynopsis>
  244. </term>
  245. <listitem>
  246. <para>
  247. Specifiy the default image conversion format. If none provided, the value is
  248. cleared. Otherwise, expects either "png" or "jpeg".
  249. </para>
  250. </listitem>
  251. </varlistentry>
  252. <varlistentry id="zend.view.helpers.initial.tiny-src.methods.set-default-dimensions">
  253. <term>
  254. <methodsynopsis>
  255. <methodname>setDefaultDimensions</methodname>
  256. <methodparam>
  257. <funcparams>$width = null, $height = null</funcparams>
  258. </methodparam>
  259. </methodsynopsis>
  260. </term>
  261. <listitem>
  262. <para>
  263. Set the default dimensions for image conversion. If no <varname>$width</varname>
  264. is specified, an empty value is provided for all dimensions (setting the height
  265. requires a width as well). Passing no value for the height will set only a
  266. width. Dimensions should be specified as either pixel dimensions, or:
  267. </para>
  268. <itemizedlist>
  269. <listitem>
  270. <para>
  271. A pixel value, preceded by a "-" sign. This will indicate the width
  272. should take the entire screen size, minus the number of pixels
  273. specified.
  274. </para>
  275. </listitem>
  276. <listitem>
  277. <para>
  278. A percentage of the total screen dimensions, expressed as "x" followed
  279. by the percentage: "x20" is equivalent to 20%.
  280. </para>
  281. </listitem>
  282. </itemizedlist>
  283. </listitem>
  284. </varlistentry>
  285. <varlistentry id="zend.view.helpers.initial.tiny-src.methods.set-create-tag">
  286. <term>
  287. <methodsynopsis>
  288. <methodname>setCreateTag</methodname>
  289. <methodparam>
  290. <funcparams>$flag</funcparams>
  291. </methodparam>
  292. </methodsynopsis>
  293. </term>
  294. <listitem>
  295. <para>
  296. Indicate whether the <methodname>tinySrc()</methodname> method should create an
  297. HTML image tag. If boolean <constant>false</constant>, only a tinysrc.net URL
  298. will be returned.
  299. </para>
  300. </listitem>
  301. </varlistentry>
  302. <varlistentry id="zend.view.helpers.initial.tiny-src.methods.create-tag">
  303. <term>
  304. <methodsynopsis>
  305. <methodname>createTag</methodname>
  306. </methodsynopsis>
  307. </term>
  308. <listitem>
  309. <para>
  310. Returns the status of the "create tag" flag.
  311. </para>
  312. </listitem>
  313. </varlistentry>
  314. </variablelist>
  315. </sect4>
  316. <sect4 id="zend.view.helpers.initial.tiny-src.examples">
  317. <title>Examples</title>
  318. <example id="zend.view.helpers.initial.tiny-src.examples.url">
  319. <title>Returning only a tinysrc.net URL</title>
  320. <para>
  321. You may want to return only a tinysrc.net URL. To do this, you have two options:
  322. make this the default behavior, or specify in your <varname>$options</varname> not
  323. to create a tag.
  324. </para>
  325. <programlisting language="php"><![CDATA[
  326. // Specifying default behavior:
  327. $this->tinySrc()->setCreateTag(false);
  328. echo $this->tinySrc('image.jpg');
  329. // Per-image:
  330. echo $this->tinySrc('image.jpg', array('create_tag' => false));
  331. ]]></programlisting>
  332. </example>
  333. </sect4>
  334. </sect3>