Page 1 of 1
Where to place function?
Posted: Fri Jul 13, 2007 2:17 am
by FantomCircuit
I am in the process of developing a few modules that include automatic image scaling in the backend. As the same image scaling function is used a few times, where would be the best place to put it? Sorry if this is a silly question, as I have only just started module development.
Re: Where to place function?
Posted: Fri Jul 13, 2007 2:22 am
by calguy1000
Well.... you can take a look at the CGExtensions module and how it's used in the FLVPlayer module.
This is an example of how I place stuff that I want to re-use that doesn't go in the core.
BTW, Image Scaling functions (unless you're doing something funky) are already provided for in ImageManager and we use these functions throughout the code. The Uploads module does this, and I can paste the code I use to call the ImageManager scaling function if you like.
Re: Where to place function?
Posted: Fri Jul 13, 2007 2:25 am
by FantomCircuit
calguy1000 wrote:
BTW, Image Scaling functions (unless you're doing something funky) are already provided for in ImageManager and we use these functions throughout the code. The Uploads module does this, and I can paste the code I use to call the ImageManager scaling function if you like.
Thanks a lot - that would be great

(as I said, I'm a n00b).
Does the ImageManger scaling support automatic cropping? That's the main reason I am using this function, as I would like the scaled image to fit in a specific image container at the exact size.
Re: Where to place function?
Posted: Fri Jul 13, 2007 2:28 am
by calguy1000
Here's a function (that I actually stole from _SjG_ I think) that does the image scaling using the ImageManager functions.
If you look in lib/filemanager/ImageManager/Classes you may see something else that will do the trick for you. I'd look here before re-inventing the wheel.
Code: Select all
function imageTransform($srcSpec, $destSpec, $size, &$config)
{
require_once(dirname(__FILE__).'/../../lib/filemanager/ImageManager/Classes/Transform.php');
$it = new Image_Transform;
$img = $it->factory($config['image_manipulation_prog']);
$img->load($srcSpec);
if ($img->img_x < $img->img_y)
{
$long_axis = $img->img_y;
}
else
{
$long_axis = $img->img_x;
}
if ($long_axis > $size)
{
$img->scaleByLength($size);
$img->save($destSpec, 'jpeg');
}
else
{
$img->save($destSpec, 'jpeg');
}
$img->free();
}