Where to place function?
- FantomCircuit
- Forum Members
- Posts: 75
- Joined: Fri Nov 10, 2006 1:34 am
- Location: Gold Coast, Australia
Where to place function?
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.
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
- Location: Fernie British Columbia, Canada
Re: Where to place function?
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.
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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
- FantomCircuit
- Forum Members
- Posts: 75
- Joined: Fri Nov 10, 2006 1:34 am
- Location: Gold Coast, Australia
Re: Where to place function?
Thanks a lot - that would be greatcalguy1000 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.

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.
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
- Location: Fernie British Columbia, Canada
Re: Where to place function?
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.
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();
}
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.