As you know, any image transformed and sent by HTML5/Flash Uploader is called thumbnail. To upload thumbnails you need to create a Converter and set its Mode property to Thumbnail. Then you should use its ThumbnailXXX properties to configure thumbnails. This topic examines resizing and recompressing settings and describes how to handle the situation when a thumbnail cannot be created.

Thumbnail Size

Note

HTML5/Flash Uploader Express and Professional restrict a size (width x height) of each created thumbnail to 3 and 5 megapixels respectively. For example, the size of 1500x1500 thumbnail is 2.25 megapixels (1500 pixels x 1500 pixels = 2.25 megapixels), thus, such a thumbnail can be uploaded with HTML5/Flash Uploader Express. See the Upload Suite Editions topic for details.

There are three settings specifying how the original image will be resized to create a thumbnail:

The ThumbnailFitMode is quite complicated, so let us describe it in detail. Fit mode is an important setting for thumbnail creation. It specifies if the thumbnail should be resized at all, and if so, how it should be shrunk to fit the specified dimensions. The ThumbnailFitMode property has the following possible values:

  • Fit means that the original image should be resized to fit the rectangle specified with the ThumbnailHeight and ThumbnailWidth properties. Note that the proportions of the original image will be kept.
  • Width means that the original image should be resized to be no wider than the ThumbnailWidth value. Image is resized proportionally, so the ThumbnailHeight property is ignored in this mode.
  • Height means that the original image should be resized to be no higher than the ThumbnailHeight value. Image is resized proportionally, so the ThumbnailWidth property is ignored in this mode.
  • ActualSize means that dimensions of the original image should be kept; however, it can be rotated or recompressed if necessary.
Note

HTML5/Flash Uploader can only downsize images, so if specified thumbnail size (ThumbnailHeight and ThumbnailWidth) is larger than size of the original image, thumbnail and the original image will be equal in size.

If you know target image DPI and size (in inches), you can calculate thumbnail width and height by multiplying target values. For example, you want to get 4"x6" image with 72 DPI, then you should set ThumbnailWidth to 432 (432 pixels = 6 inches x 72 DPI) and ThumbnailHeight to 288 (288 pixels = 4 inches x 72 DPI).

The next example illustrates how to create a thumbnail converter and set its general properties.

ASP.NET

<aur:ImageUploaderFlash ID="Uploader1" runat="server">
    <Converters>
        <aur:Converter Mode="*.*=Thumbnail" 
           ThumbnailHeight="200" 
           ThumbnailWidth="200" 
           ThumbnailFitMode="Fit" />
    </Converters>
</aur:ImageUploaderFlash>

PHP

$uploader = new ImageUploaderFlash("Uploader1");
$converters = &$uploader->getConverters();
$converter = new Converter();
$converter->setMode("*.*=Thumbnail");
$converter->setThumbnailWidth(200);
$converter->setThumbnailHeight(200);
$converter->setThumbnailFitMode("Fit");
$converters[] = $converter;

JavaScript

var fu = $au.imageUploaderFlash({
    id: 'Uploader1',
    converters: [{mode: '*.*=Thumbnail', 
        thumbnailWidth: 200, 
        thumbnailHeight: 200, 
        thumbnailFitMode: 'Fit'}]
});

Thumbnail Quality

Important

Thumbnail quality is not supported by HTML5 Uploader.

The only thumbnail supported file format is JPEG. It means that a thumbnail will be a JPEG image whatever format an original image has. This image format has an ability to balance between file size and image quality. You can specify JPEG quality of a thumbnail via the ThumbnailJpegQuality property which accepts a number in the range [0, 100]. If you specify 0, the file will be extremely small, but the quality will be very low (almost always unacceptable). Alternatively, if you specify 100, the file will be quite large, but JPEG artifacts will be almost invisible. Usually, small images have rather low quality (to be loaded quickly), whereas screen-size images have higher quality. The default ThumbnailJpegQuality value is 80 which is the most balanced and common JPEG quality.

Note

If you set the JPEG quality to a large value, and upload a JPEG file that has poor quality initially, the file size may increase (although the quality will not become better). It is not guaranteed that the output JPEG will have the same or less size than the original file. This effect is caused by specificity of JPEG compression algorithm.

That is why if you expect that users will upload poor-quality JPEG files, it makes sense to set the quality to a low value.

Handling Image Transparency

All the thumbnails are created as JPEG images, and the JPEG format does not support transparency. That does not mean that you will be unable to create thumbnails for transparent images. The thumbnails will simply be created on a background of some color. You can set this color using the ThumbnailBgColor property. To specify desired background color use a hex representation of the RGB triad in HTML-style syntax (#rrggbb). Default background color is white (#FFFFFF).

If Thumbnail Cannot be Created

It is possible that some specific thumbnail will fail to be created, for example, when the original file is corrupted or it is non-image. To handle this situation specify one more conversion mode (e.g. SourceFile or Icon) after the Thumbnail one. In this case, if applying of the first mode has failed, HTML5/Flash Uploader will try to use the next one.

The following example illustrates the idea.

ASP.NET

<aur:ImageUploaderFlash ID="Uploader1" runat="server">
    <Converters>
        <%-- Send the source file if the thumbnail cannot be created --%>
        <aur:Converter Mode="*.*=Thumbnail;*.*=SourceFile" />
        <%-- Send an icon if the thumbnail cannot be created --%>
        <aur:Converter Mode="*.*=Thumbnail;*.*=Icon" />
    </Converters>
</aur:ImageUploaderFlash>

PHP

$uploader = new ImageUploaderFlash("Uploader1");
$converters = &$uploader->getConverters();
$converter = new Converter();
//Send the source file if the thumbnail cannot be created
$converter->setMode("*.*=Thumbnail;*.*=SourceFile");
$converters[] = $converter;
$converter = new Converter();
//Send an icon if the thumbnail cannot be created
$converter->setMode("*.*=Thumbnail;*.*=Icon");
$converters[] = $converter;

JavaScript

var fu = $au.imageUploaderFlash({
    id: 'Uploader1',
    converters: [
        //Send the original file if the thumbnail cannot be created
        {mode: '*.*=Thumbnail;*.*=SourceFile'}, 
        //Send an icon if the thumbnail cannot be created
        {mode: '*.*=Thumbnail;*.*=Icon'}
    ]
});

See Also

Reference

Manual