resizing images after upload

Phoca Gallery - image gallery extension
lancerus
Phoca Member
Phoca Member
Posts: 15
Joined: 16 Feb 2010, 14:35

resizing images after upload

Post by lancerus »

The web provider I use has some strict process memory clamps, which means thumbnail creation crashes the web site unless I restrict uploaded images to something relatively small compared to today's cameras. What I did to solve this and keep my site friendly is still allow large images to get uploaded - but immediately resize them with an exec to convert after the upload. The code goes in controllers/ user.php and category.php. I can provide the code if interested.
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 49297
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: resizing images after upload

Post by Jan »

Hi, you can display the code here, but I think the exec is disabled on most servers :-(

Jan
If you find Phoca extensions useful, please support the project
lancerus
Phoca Member
Phoca Member
Posts: 15
Joined: 16 Feb 2010, 14:35

Re: resizing images after upload

Post by lancerus »

Here's an example. For hosts that dont support exec - resizing could be changed to do it in-line, then you'd have it covered for both the java path (client-side) or singleFileUpload path (server side). I have my resize size hard-coded at the moment as you can see. I cant do the in-line resize due to the memory size problem again. I tried that path first.

Code: Select all

                       if (!JFile::upload($file['tmp_name'], $filepath)) {
                                $errUploadMsg = JText::_("Unable to upload file");
                                $redirectUrl = $return;
                                return false;
                        } else {
                                // resize the uploaded image if required.
                                list($w,$h) = getimagesize($filepath);
                                if ($w > 1600 && $h > 1600) {
                                    $cmd = "convert -resize 1600x \"$filepath\" \"$filepath\"";
                                    exec($cmd, $output, $retval);
                                    // if ($retval) we failed ...
                                    if ($retval) {
                                        $errUploadMsg = JText::_("Unable to resize file");
                                        $redirectUrl = $return;
                                        return false;
                                    }
                                }
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 49297
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: resizing images after upload

Post by Jan »

Ok, thank you for this info.

Jan
If you find Phoca extensions useful, please support the project
bepos
Phoca Newbie
Phoca Newbie
Posts: 2
Joined: 24 Aug 2009, 21:07

Re: resizing images after upload

Post by bepos »

nice solution. But can you be a bit more specific where to put the code in the files?
Post Reply