ThumbGeneratorAdapter bugging?

Dec 21, 2008 at 8:30 PM

My problem: Resizing isn't working, more specifically: MaximumWidth isn't working if the images (only tried jpg) height is higher then it's width.
Some examples with maxwidth and height set to 150:
Fail:
Original image: 500x200 (higher height then width)
Thumb: 150x200 (should be 90x150)

Success:
Original image: 200x500 (lower height then width)
Thumb: 150x90 (as it should)

My code:
<fjx:FileUploader
ID="Uploader"
MaxFileSize="1MB"
MaxFileSizeReachedMessage="Filen får högst vara {0} stor."
AllowedFileTypes="Tillåtna filtyper:*.rtf;*.doc;*.xls;*.docx;*.jpg;*.jpeg;*.png;*.gif;*.txt;"
JsFunc_PositionFilesList="PositionFilesListFunc"
JsFunc_FileStateChanged="FileStateChanged"
RequestAsPostBack="true"
runat="server"
>
<Adapters>
<fjx:FileSaverAdapter></fjx:FileSaverAdapter>
<fjx:ThumbGeneratorAdapter runat="server" Extensions="jpg;jpeg;png;gif" MaximumHeight="150" MaximumWidth="150" />
</Adapters>
</fjx:FileUploader>

(foldername is set in codebehind)

Coordinator
Dec 21, 2008 at 10:32 PM
Hi Kani,

I just tested it and I see that the adapters work fine. It must be something you do on  the code behind.

For example I see that you don't use Suffix or Prefix properties of the Thumb Generator adapter so if you store thumbs in the same folder as images, the images one can override the other, but even then the hight - width ratio will be the same. So I have no idea what is your problem. I cannot repeat it. If you can isolate the problem and send the code I can look at it.
Dec 22, 2008 at 3:44 PM

Here is an example of what my code looks like, and also including

http://sasavi.mine.nu/test/flajaxian_upload_example.zip

If you want to try upload to my server and see the result you can use:
http://sasavi.mine.nu/test/ <- uploader
http://sasavi.mine.nu/test/Upload/ <- uploaded files
http://sasavi.mine.nu/test/Thumbs/ -<- thumbnails

Coordinator
Dec 22, 2008 at 4:18 PM
That is strange cause on my computer your code works fine.

I see that you use version 2.0.3265. Can you try with the latest version, though I didn't change thumb generator for a long time.

Did you see the same problem on different computers?

It may be that you have different version of GDI...
Dec 22, 2008 at 5:05 PM

Yes I suspected it to be the version too.

I thought I'm using the latest version, I took it from the download button at http://www.codeplex.com/FlajaxianFileUpload

Where can I find a newer version?

Dec 22, 2008 at 5:17 PM

Ok now I found it and it seems to be working. So I probably had an old version.

The "Download Now" button I mentioned above seems to link to an old version.

Coordinator
Dec 22, 2008 at 5:33 PM
OK it's still strange as I did not change thumb generator recently...
Dec 22, 2008 at 5:59 PM

My bad.. actually, this is getting a bit strange.

I downloaded it again and put it in the bin folder, tried upload some files and it worked..

But now it's not working again, I even tried download the latest source and compile it myself. But I keep getting the same problem... just no idea why it worked for a few sec back there..

Dec 22, 2008 at 6:36 PM
Edited Dec 23, 2008 at 8:31 AM

I checked the source and foundthe part that handles resizing, and it wasn't coded correctly:

I changed

double ratio = image.Width / (double)image.Height;
int width = maxWidth;
int height = (int)Math.Round(width / ratio);
if (height > maxHeight)
{
height = maxHeight;
width = (int)Math.Round(image.Height * ratio);
}

into 

double ratio;
int height;
int width;
if (image.Width > image.Height)
{
ratio = image.Width / (double)image.Height;
width = maxWidth;
height = (int)Math.Round(width / ratio);
if (height > maxHeight)
{
height = maxHeight;
width = (int)Math.Round(image.Height * ratio);
}
}
else
{
ratio = image.Height / (double)image.Width;
height = maxHeight;
width = (int)Math.Round(height / ratio);
if (width > maxWidth)
{
width = maxWidth;
height = (int)Math.Round(image.Width * ratio);
}
}

I'm not sure if it's the smoothest way to do it but it solved my problem.
Note that the bug only happened with images with higher height then width.. now I just added an if that checks if width or heightis higher and handles the resizing accordingly.

Coordinator
Dec 22, 2008 at 8:03 PM
Edited Dec 22, 2008 at 8:06 PM
OK Thanks I will check that later, may be the algorithm need optimization
Dec 23, 2008 at 8:59 AM
Yea, and thanks for the help :)
Jan 26, 2009 at 12:41 PM
Thumbs are not created if uploading files with spaces in the name...
Could be a solution replace spaces with _ char?
Coordinator
Jan 26, 2009 at 5:52 PM
There is no problem with spaces.

Most probably you use the same folder for thumbs and files and you don't use Prefix or Suffix so one overrides the other.