File Upload Error with image re-sizing

Status
Not open for further replies.

crowden

New Member
Hi,

Using Fabrik 1.0.5

I was receiving an error on a form I had created to upload images. On the element setup, I omitted a width on the image size field because I wanted the image to keep it's aspect ratio instead of forcing a width that makes the image look too fat or too thin.

So, when Fabrik looks for the $maxWidth property, it is never set. That gave me this error:

-------------------------------------------------------
Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\wamp\www\fabrik\components\com_fabrik\fabrik.class.php on line 3551

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\wamp\www\fabrik\components\com_fabrik\fabrik.class.php on line 3554
no image created for C:\wamp\www\fabrik\flash\biglogos\103_1109_JPG.jpg, extension = jpg
-------------------------------------------------------

I went in to the fabrik.class.php file to the lines specified and added the following to line 3541:
-------------------------------------------------------
if($maxWidth < 20){
$maxWidth = round((($maxHeight * $width) / $height));
}
-------------------------------------------------------

This locks in the correct aspect ratio for the $maxWidth when $maxHeight is set in the element setup. (I set it to see if it's less than 20, just a random number I picked to make sure the width isn't set correctly...probably could be 1)

Of course, this is specific to my problem. If you don't set a $maxHeight in the element setup, this won't work. More tweaking is necessary to check that and to assign resizing variables appropriately.

I hope this helps anybody that has experienced this. As always, any pointers on something I could have done differently are welcome.

Cheers!
 
What version is this? 1.0.5.2 ZIP, another ZIP, or an SVN? Those line numbers don't quite jive with the latest file.

As far as I can tell, resize() shouldn't alter the aspect ratio when you specify both width and height, because of this code:

PHP:
            $width = imagesx($img);
            $height = imagesy($img);
            $scale = min($maxWidth / $width, $maxHeight / $height);
            /* If the image is larger than the max shrink it*/
            if ($scale < 1) {
                $new_width = floor($scale * $width);
                $new_height = floor($scale * $height);
                /* Create a new temporary image*/
                $tmp_img = imagecreatetruecolor($new_width, $new_height);
                ... blah blah ...
            }

In other words, it uses the smallest of the two ratios to scale the whole image with.

The reason it's blowing up in resize() is 'cos we aren't checking that both maxHeight and maxWidth are set before calling it, so the scale ends up being 0. At least, when creating a thumb. We are checking when applying the main image resize (a feature we may have added since your version, not sure).

So ... make sure you are running the latest SVN with the current resize code, and simply specify both width and height. Should scale to just one of them, preserving aspect ratio.

If it doesn't, let me know. Meanwhile I'll fix things so we police the setting of both values.

-- hugh
 
Wow, don't know what I was thinking.

Thanks!

So both the height and width settings on the element setup should be required. There's no mention of those fields in the manual, by the way (Fabrik1.0_manual_rev1.0.5.pdf), unless I used the wrong link to download the manual...
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top