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.


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.


4 Posts   2624 Views


11 October 2007 at 5:03am (Last edited: 11 October 2007 5:28am), Community Member, 501 Posts


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:

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...


11 October 2007 at 5:46am (Last edited: 11 October 2007 5:50am), Community Member, 501 Posts

Ok, another approach:

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

Am I going in the right direction?


11 October 2007 at 6:45am Community Member, 501 Posts

Forget it, I solved it :-)


2 May 2008 at 9:22pm Community Member, 46 Posts

Hey dio5,

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