Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Automatic Resizing of images uploaded on frontend.


Reply


4 Posts   2680 Views

Avatar
dio5

Community Member, 501 Posts

11 October 2007 at 5:03am

Edited: 11/10/2007 5:28am

Hi,

I let users upload images through the frontend and I want them to be resized immediately if they are bigger than 800x800.

Now I thought I could use some of SS's methods like 'generateResizedImage()' but I'm a bit stuck with that.

I get the original from the File-table based on an ID.
So I have a 'image' dataobject. Now I want to replace the original with the resized.
What I have already is this:

$photo = DataObject::get_by_id("File", $tip->PhotoID);
            
$width = $photo->getWidth();
$height = $photo->getHeight();
if($width > $height && $width > 800)
{
$newWidth = 800;
$ratio = $width/$newWidth;
   $newHeight = $height/$ratio
}
if($width < $height && $height > 800)
{
   $newHeight = 800;
   $ratio = $height/$newHeight;
   $newWidth = $width/$ratio;
}
if($newWidth && $newHeight)
{
   $resized = $photo->generateResizedImage($newWidth, $newHeight);
// do some stuff with the resized.. replace original with resized..?
}

Now there seems to be a parameter missing in the generateResizedImage(???, $width, $height), but there' s nothing about it in the docu:
[url]http://doc.silverstripe.com/assets/classes/default/Image.html#generateResizedImage[/url]

I suppose it is $gd, but what is that $gd?

If someone could hint me how to resize the original image using SS that would be great. Otherwise I'm just going to use some plain php...

Avatar
dio5

Community Member, 501 Posts

11 October 2007 at 5:46am

Edited: 11/10/2007 5:50am

Ok, another approach:

if($newWidth && $newHeight)
{
$GDImage = new GD("../" . $photo->Filename);
   $GDImage->resize($newWidth, $newHeight);
               
}

Am I going in the right direction?

Avatar
dio5

Community Member, 501 Posts

11 October 2007 at 6:45am

Forget it, I solved it :-)

Avatar
fordy

Community Member, 46 Posts

2 May 2008 at 9:22pm

Hey dio5,

could you post you solution for resizing on front-end upload?

Cheers

Ed