MonoX support board

Start the conversation, ask questions and share tips and solutions with fellow developers.

Non-registered users can only browse through our support boards. Please register now if you want to post your questions. It takes a second and it is completely free. Alternatively, you can log in without registration using your credentials at major sites such as Google, Microsoft Live, OpenId, Facebook, LinkedIn or Yahoo.

Thumbnail quality and autoscaling avatar (Closed) (Mono Support )

Viewed 23537 time(s), 4 post(s) 6/26/2011 12:09:28 PMby testmmi
testmmi

testmmi

6/26/2011 12:09:28 PM
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
This content has not been rated yet. 
93 Reputation 11 Total posts
khorvat

khorvat

6/26/2011 6:18:53 PM
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



This content has not been rated yet. 
15993 Reputation 2214 Total posts
khorvat

khorvat

6/27/2011 10:42:40 AM
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
This content has not been rated yet. 
15993 Reputation 2214 Total posts
testmmi

testmmi

6/27/2011 10:51:39 AM
thanks for your fast help, i will implement it in my solution

best regards
Markus
This content has not been rated yet. 
93 Reputation 11 Total posts