Imagemagick sfThumbnail Plugin Fix for Scaling under Symfony
I've been using the sfThumbnail Plugin in symfony for image resizing when users upload. When I asked the plugin to resize an image with scaling there was a problem and the image came out skewed and distorted. After a little research I found the following fix.
Once you have installed the plugin, edit the sfImageMagickAdapter.class.php in the plugin dir.
Change lines 223-237:
$width = $this->sourceWidth; $height = $this->sourceHeight; $x = $y = 0; switch (@$this->options['method']) { case "shave_all": if ($width > $height) { $x = ceil(($width - $height) / 2 ); $width = $height; } elseif ($height > $width) { $y = ceil(($height - $width) / 2); $height = $width; }
to:
$width = $this->sourceWidth; $height = $this->sourceHeight; $mWidth = $this->maxWidth; $mHeight = $this->maxHeight; $x = $y = 0; switch (@$this->options['method']) { case "shave_all": if ($width > $height) { $x = ceil(($width - ($height*$mWidth)/$mHeight) / 2 ); $width = $height; } elseif ($height > $width) { $y = ceil(($height - $width*($mHeight/$mWidth)) / 2); $height = $width; }
It's a straight forward edit so you should be able to see why this simple change has the desired effect, and your images will now behave nicely when scaling.
HOWTO: collapse the web debug toolbar in symfony by default
To automatically collapse, hide, shrink (or whatever you want to call it) the web debug toolbar to just the SF and close buttons; add this line
window.onload=sfWebDebugToggleMenu;
to the end of this file ...\symfony\web\sf\sf_web_debug\js\main.js
This handy little tip courtesy of IsRobot.
Using helpers within an action in symfony
If you ever need to use a helper outside a template, you can still load a helper group from anywhere by calling
sfLoader::loadHelpers($helpers)
where $helpers is a helper group name or an array of helper group names.
For instance, if you want to use simple_format_text() in an action, you need to call
sfLoader::loadHelpers('Text');
first.
I know this is covered in the symfony docs but it's a fairly handy thing to know so thought I would make it easier to find.