Mono Support Thumbnail quality and autoscaling avatar (Closed)

Viewed 43057 time(s), 4 post(s), 6/26/2011 12:09:28 PM - by testmmi
6/26/2011 12:09:28 PM
93 Reputation 11 Total posts

Hi,

is it possible out of the box, to customize the quality of thumbs in the gallery. I want to adjust a lower compression rate to get better image quality at the cost of size.

it would be nice to have a feature like auto crop for avatar images. If i upload an image with different aspect ratio the image would get distort in the avatar image box.
is there a workaround, or can i adapt my own handler to replace the current one.

thank 4 any advice and for your great product,
kind regards
Markus

1
6/26/2011 6:18:53 PM
15993 Reputation 2214 Total posts

Hi,

the avatar thumbs size can be changed by setting the below size in the web.config

<!-- thumbnail size: Small (72px), Medium (144 px), Large (288 px) -->
<add key="ThumbnailSize" value="Small" />

The gallery thumbs size and quality can't be changed at the moment but I'll try to find the workaround tomorrow and get back to you. As for auto crop functionality we will try to put in on our feature list for new MonoX releases.

Regards



2
6/27/2011 10:42:40 AM
15993 Reputation 2214 Total posts

Hi,

I have made some changes to enable the image quality settings modifications, you can find the unofficial MonoX patch (4.1.2575) in the attachment.

To implement custom image quality settings you need to do the following:

1. Create your own upload handler by inheriting from MonoSoftware.MonoX.SilverlightUploadHandler
2. Override the SaveThumbnail method which will be called on every image upload in the MonoX 
- here you can create or resize uploaded images 
- existing code looks like this (MonoX version 4.1.2741):

protected virtual void SaveThumbnail(string filePath, IFileContentProvider provider)
{
    foreach (ThumbnailSizeType item in Enum.GetValues(typeof(ThumbnailSizeType)))
    {               
        Image thumbnail = ImageUtility.CreateThumbnail(filePath, (int)item);
        try
        {
            using (MemoryStream stream = new MemoryStream())
            {
                thumbnail.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);                       
                string newFilePath = ImageUtility.GetThumbnailFileName(filePath, item);
                provider.StoreFile(stream, newFilePath);
            }
        }
        catch { }
        finally
        {
            thumbnail.Dispose();
        }
    }
}

- as you can see we are pre-creating all the thumbnails and here you can use almost the same code as above but with small change, you need to call the ImageUtility.CreateThumbnail with your custom image size. If you want to change the image resize quality settings then you can use method overload that has an MonoSoftware.Core.Drawing.ImageFormatterEventArgs which exposes even more settings.

Regards

3
6/27/2011 10:51:39 AM
93 Reputation 11 Total posts

thanks for your fast help, i will implement it in my solution

best regards
Markus

4
This is a demo site for MonoX. Please visit Mono Software for more info.