Development

Changeset 7944

You must first sign up to be able to contribute.

Changeset 7944

Show
Ignore:
Timestamp:
03/18/08 12:36:02 (5 years ago)
Author:
naholyr
Message:

[sfThumbnailPlugin] edit README to add chapter about sfThumbnailHelper

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfThumbnailPlugin/README

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

    r7941 r7944  
    4848/** 
    4949 * Get the <img> tag to include a thumbnail into your web page 
     50 * Options are the same than the ones used in image_tag() 
    5051 * 
    5152 * @param string $source 
    5253 * @param int $width 
    5354 * @param int $height 
    54  * @param mixed $options 
     55 * @param mixed $options  
    5556 * @return string 
    5657 */ 
    5758function thumbnail_tag($source, $width, $height, $options = array()) 
    5859{ 
    59   $img_src = thumbnail_path($source, $width, $height, false); 
     60  $img_src = thumbnail_path($source, $width, $height); 
     61 
    6062  return image_tag($img_src, $options); 
    6163}