## QPix v2.2x | ## An image database step by step

Chapter index | Step: 1 - 2 - 3 - 4 - 5 - 6

# Step 5: Compressing the thumbnail

Who needs compression?

Even small pictures are huge compared to other kinds of data: a typical small thumbnail occupies 20K, roughly the same as 10 pages of plain text or a 4D set for 165000 records!

Image thumbnails are usually kept inside the 4D datafile and, as we want our datafile to remain as small as possible, reducing the size of thumbnails isn’t such a bad idea. In fact, the need for compression is inherent in image databases.

QuickTime does compression

QPix provides access to QuickTime compression services, which makes compressing images easy and efficient. We should let our users decide about compression, because good compression is lossy and users may not like loss of image quality in certain cases.

To let users choose a compression method, quality and color depth of the compressed thumbnail, we invoke QuickTime's compression settings dialog using the QPx_DoCodecSettingsDialog command. While choosing compression settings, the user can see how the thumbnail will eventually look like:

``Ask the user for compression settings` `C_STRING``(4;$codec) `The compressor identifier` `C_LONGINT``($quality) `Compression quality` `C_LONGINT``($depth) `Pixel depth of the compressed thumbnail` `$error:=QPx_DoCodecSettingsDialog($codec;$quality;$depth)` `If``($error=qpx_noErr)` ``User has selected compression settings successfully` `End if`

We can now compress the thumbnail and create the database record:

``Compress the thumbnail with the selected settings` `$error:=QPx_CompressPicture($thumbnail;$codec;$quality;$depth)` `If``($error=qpx_noErr)` ``The thumbnail was compressed successfully, create a database record` `CREATE RECORD``([Images])` `[Images]xThumbnail_:=$thumbnail` `[Images]FullPath:=$imageFilePath` `[Images]Width:=$width` `[Images]Height:=$height` `[Images]Depth:=$depth` `[Images]HorzRes:=$hRes` `[Images]VertRes:=$vRes` `SAVE RECORD([Images])` `End if`

| Sometimes you may need to decompress a compressed picture. To do this, compress it with the "raw " codec (there is a space at the end of the codec name — don’t miss it!): $error:=QPx_CompressPicture($thumbnail;"raw ";1024;0)

Go to Step 6