| | 103 | === Create thumbnails "on the fly" using sfThumbnailHelper === |
|---|
| | 104 | |
|---|
| | 105 | You can generate your thumbnails on demand, using the included helpers. |
|---|
| | 106 | |
|---|
| | 107 | {{{ |
|---|
| | 108 | // Include the helper |
|---|
| | 109 | <?php use_helper('sfThumbnail') ?> |
|---|
| | 110 | }}} |
|---|
| | 111 | |
|---|
| | 112 | Two helpers are provided, very similar to image_* helpers : |
|---|
| | 113 | |
|---|
| | 114 | {{{ |
|---|
| | 115 | // Returns path to the generated thumbnail |
|---|
| | 116 | thumbnail_path($source_image, $thumbnail_width, $thumbnail_height, $absolute = false) |
|---|
| | 117 | |
|---|
| | 118 | // Returns the <img> tag to display the generated thumbnail |
|---|
| | 119 | thumbnail_tag($source_image, $thumbnail_width, $thumbnail_height, $options = array()) |
|---|
| | 120 | }}} |
|---|
| | 121 | |
|---|
| | 122 | These helpers are very simplistic, and for the moment do not handle advanced options |
|---|
| | 123 | that could be passed to sfThumbnail constructor. It just allows you to replace your |
|---|
| | 124 | image_tag() and image_path() calls with thumbnail_*() calls, just adding the wished |
|---|
| | 125 | size. |
|---|
| | 126 | |
|---|
| | 127 | The thumbnail is generated only if the destination file does not exist or if the source |
|---|
| | 128 | is newer than the destination. |
|---|
| | 129 | |
|---|
| | 130 | The thumbnails are saved into a given directory, with the same structure than the source |
|---|
| | 131 | file. Default directory is "uploads/thumbnails". |
|---|
| | 132 | |
|---|
| | 133 | {{{ |
|---|
| | 134 | thumbnail_tag('path/to/myImage.jpg', 100, 100) |
|---|
| | 135 | // Will generate /uploads/thumbnails/path/to/myImage_100x100.jpg |
|---|
| | 136 | }}} |
|---|
| | 137 | |
|---|
| | 138 | The directory can be defined in your app.yml file, without any trailing slash. |
|---|
| | 139 | |
|---|
| | 140 | {{{ |
|---|
| | 141 | all: |
|---|
| | 142 | sfThumbnail: |
|---|
| | 143 | thumbnails_dir: uploads/thumbnails |
|---|
| | 144 | }}} |
|---|
| | 145 | |
|---|