I'm using the sfImageTransformPlugin in conjunction with the helpers
below:


/**
 * Get the path of a generated thumbnail for any given image
 *
 * @param string $source
 * @param int $width
 * @param int $height
 * @param boolean $absolute
 * @return string
 */
function thumbnail_path($source, $width = null, $height = null,
$absolute = false)
{
        $thumbnails_dir = sfConfig::get('app_sfThumbnail_thumbnails_dir',
'uploads/thumbnails');
        $quality = sfConfig::get("app_sfThumbnail_quality", 90);

        $width = intval($width);
        $height = intval($height);

        if (substr($source, 0, 1) == '/') {
                $realpath = sfConfig::get('sf_web_dir') . $source;
        } else {
                $realpath = sfConfig::get('sf_web_dir') . '/images/' . $source;
        }

        $real_dir = dirname($realpath);
        $thumb_dir = '/' . $thumbnails_dir . substr($real_dir,
strlen(sfConfig::get('sf_web_dir')));
        $thumb_name = preg_replace('/^(.*?)(\..+)?$/', '$1_' . $width . 'x' .
$height . '$2', basename($source));

        $img_from = $realpath;
        $thumb = $thumb_dir . '/' . $thumb_name;
        $img_to = sfConfig::get('sf_web_dir') . $thumb;

        if (!is_dir(dirname($img_to))) {
                if (!mkdir(dirname($img_to), 0777, true)) {
                        throw new Exception('Cannot create directory for 
thumbnail : ' .
$img_to);
                }
        }

        if (!is_file($img_to) || filemtime($img_from) > filemtime($img_to)) {

        if(!sfConfig::get("app_sfThumbnail_safe_mode", true) ||
file_exists($img_from)) {
          $thumbnail = new sfImage($img_from);
          $thumbnail -> thumbnail($width, $height, 'scale');
          $thumbnail -> setQuality($quality);
          $thumbnail -> saveAs($img_to);
        }
        }

        return image_path($thumb, $absolute);
}

/**
 * Get the <img> tag to include a thumbnail into your web page
 *
 * @param string $source
 * @param int $width
 * @param int $height
 * @param mixed $options
 * @return string
 */
function thumbnail_tag($source, $width, $height, $options = array())
{
        $img_src = thumbnail_path($source, $width, $height, false);
        return image_tag($img_src, $options);
}





This way you can call thumbnail_tag('...path to image', 200, 200); and
the conversion is happening on the fly - once.

Daniel


On Oct 18, 12:33 am, Alan Bem <alan....@gmail.com> wrote:
> Use sfImageTransformExtraPlugin - it is very easy to use, customizable
> plugin, that requires almost nothing to make it work (transparently).
>
> 2010/10/17 xpanshun <srhen...@gmail.com>
>
> > How would I call to this class from my indexSuccess.php to get the
> > images to resize as they are displayed?
>
> > *See coding in original post
>
> > On Oct 17, 2:43 pm, Martin Ibarra Cervantes
> > <ibarra.cervan...@gmail.com> wrote:
> > > hi, you can try use this class with sfThumbnailPlugin
>
> > >http://mic.misretratos.com/2010/10/17/sfresizedfile/
>
> > > regards.
>
> > > On Sun, Oct 17, 2010 at 9:45 AM, xpanshun <srhen...@gmail.com> wrote:
> > > > Hi all,
>
> > > > I am trying to create a product gallery on the front end of my site.
>
> > > > In my database a have a product table with a field containing the path
> > > > to the image for each product called 'product_img_path'. I can bring
> > > > up each product image with the following coding:
>
> > > > <table>
> > > >  <?php foreach ($products as $product): ?>
> > > >    <tr>
> > > >            <td>
> > > >                  <?php echo image_tag($product->getProductImgPath()) ?>
> > > >            </td>
> > > >    </tr>
> > > >  <?php endforeach; ?>
> > > > </table>
>
> > > > The problem is: these are full size images. I want to create
> > > > thumbnails with the sfThumbnailPlugin plugin, but I don't know how or
> > > > where to code it correctly to make it work.
>
> > > > I've found a few tutorials utilizing several other plugins for an
> > > > image gallery, but they are either for Propel users (I use doctrine)
> > > > or uploading images. I have these images in a file directory and plug
> > > > them in to the database for each product. I'm sure there are ways
> > > > around my issue, but I really wanted to use the sfThumbnailPlugin
> > > > alone.
>
> > > > Please, how can I use sfThumbnailPlugin to shrink my images on the
> > > > index page? [I don't necessarily want to have to save these thumbnails
> > > > either, if possible]
>
> > > > P.S. I understand everyone has their own opinions on which ways are
> > > > best to make image galleries or have images in your database, but
> > > > please if there is just a solution to the way I have it set up here I
> > > > would appreciate it.
>
> > > > Thanks in advance!
>
> > > > --
> > > > If you want to report a vulnerability issue on symfony, please send it
> > to security at symfony-project.com
>
> > > > You received this message because you are subscribed to the Google
> > > > Groups "symfony users" group.
> > > > To post to this group, send email to symfony-users@googlegroups.com
> > > > To unsubscribe from this group, send email to
> > > > symfony-users+unsubscr...@googlegroups.com<symfony-users%2bunsubscr...@googlegroups.com>
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/symfony-users?hl=en
>
> > --
> > If you want to report a vulnerability issue on symfony, please send it to
> > security at symfony-project.com
>
> > You received this message because you are subscribed to the Google
> > Groups "symfony users" group.
> > To post to this group, send email to symfony-users@googlegroups.com
> > To unsubscribe from this group, send email to
> > symfony-users+unsubscr...@googlegroups.com<symfony-users%2bunsubscr...@googlegroups.com>
> > For more options, visit this group at
> >http://groups.google.com/group/symfony-users?hl=en

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to