/**
  * Set up form
  */
 public function setup()
 {
     parent::setup();
     $this->setWidget('sf_image_id', new sfWidgetFormInputHidden());
     $this->setWidget('cropped_image', new sfWidgetFormInputFile());
     // Override from the default options
     $options = array('required' => true, 'path' => null);
     $this->setValidator('cropped_image', new sfValidatorImageFile(sfImagePoolUtil::getValidatorOptions($options), sfImagePoolUtil::getValidatorMessages()));
     $this->useFields(array('sf_image_id', 'cropped_image'));
 }
 /**
  * Find all files in the sfImagePool filesystem with the given
  * name (i.e. all the resized versions) and delete them.
  * 
  * Also need to delete sfImagePoolCrops - as the image itself has changed
  * this will handle deleting off the cloud
  * 
  * @param string $filename Old file to delete
  */
 public function deleteCached($filename, $image = null)
 {
     $count = sfImagePoolUtil::deleteImageFile($filename);
     if ($image) {
         $crops = $image->getCrops();
         if (0 < $crops->count()) {
             foreach ($crops as $crop) {
                 // Delete crop - interfaces with Cache
                 $crop->delete();
                 $crop->free();
             }
         }
     }
 }
 /**
  * A generic upload action for creating new images and saving them
  * with tags, not not associating with any object.
  * 
  * A straight forward add to pool action. Written to allow integration with other plugins
  * or uploading contexts which don't involve the admin gen and an sfImagePoolImage form.
  * Handles multiple files, all with same tags. Good for WYSIWYG editor integration.
  * 
  * Checks for a 'tag' field name and uses this to add tags. Can be
  * a CSV list or a single string.
  * 
  * Only works with POST data, doesn't aim to replace any data (PUT).
  */
 public function executeUpload(sfWebRequest $request)
 {
     $this->forward404Unless($request->isMethod('post'));
     // process each upload one by one
     foreach ($request->getFiles() as $upload) {
         // first do checks for standard php upload errors, as we probably won't have
         // an uploaded file to deal with at all, so need the correct error message.
         $errors = sfImagePoolUtil::getUploadErrors($upload);
         // spit out any errors we've got and halt right here.
         if (count($errors)) {
             $message = sprintf('<ul><li>%s</li></ul>', implode('</li><li>', $errors));
             return $this->renderText($message);
         }
         sfImagePoolUtil::createImageFromUpload($upload, $tags);
     }
     return sfView::NONE;
 }
/**
 * Output image of given size for an sfImagePoolImage.
 *
 * @param mixed $invoker Model or sfImagePool image
 * @param string $dimensions e.g. 'crop=200x150' or '200' for fit to 200 width (scale is default)
 * @param mixed $options either string or array, e.g. array('method' => 'scale', 'require_size' => true)
 * @param string $attributes HTML attributes, such as width, height and alt
 * @param boolean $absolute return absolute URL for an image
 * @return string
 * @author Jimmy Wong
 */
function pool_image_tag($invoker, $dimensions = 200, $options = 'crop', $attributes = array(), $absolute = false)
{
    // remove Symfony escaping if applied
    if ($invoker instanceof sfOutputEscaper) {
        $invoker = $invoker->getRawValue();
    }
    // attempt to fetch associated sfImagePoolImage
    $image = $invoker instanceof sfImagePoolImage ? $invoker : $invoker->getFeaturedImage();
    if (is_array($dimensions)) {
        $w = $dimensions[0];
        $h = $dimensions[1];
    } else {
        if (strpos(strtolower($dimensions), 'x') !== false) {
            list($w, $h) = explode('x', $dimensions);
        } else {
            $h = $w = $dimensions;
        }
    }
    if (is_array($options)) {
        $method = array_key_exists('method', $options) ? $options['method'] : 'crop';
    } else {
        $method = $options;
        $options = array();
    }
    $pool_image_uri = pool_image_uri($image, array($w, $h), $method, $absolute);
    // We need the actual image dimensions so the space is correct on the page
    if (array_key_exists('require_size', $options) && true == $options['require_size']) {
        // Only if we're scaling it - get the image size
        if ('scale' == $method) {
            list($attributes['width'], $attributes['height']) = sfImagePoolUtil::calculateWidthAndHeight($image, $w, $h);
        } else {
            $attributes['width'] = $w;
            $attributes['height'] = $h;
        }
    }
    $attributes = _sf_image_pool_build_attrs($image, array($w, $h), $method, $attributes);
    return image_tag($pool_image_uri, $attributes);
}
 public function addMultipleUploadFields($field_name = 'image', $nb_images = 5)
 {
     sfImagePoolUtil::addMultipleUploadFields($this, $field_name, $nb_images);
 }
 /**
  * Delete files in image pool folder - including all thumbnails
  * This is used by all cache implementations as the original file is stored on the filesystem
  * The main delete is only used to remove files if no crop sent through
  * 
  * @author Jo Carter
  */
 public function delete(sfImagePoolCrop $crop = null)
 {
     if (!is_null($crop)) {
         $count = sfImagePoolUtil::deleteImageFile($this->image['filename']);
     }
 }