diff options
| author | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2010-10-09 21:20:13 +0200 |
|---|---|---|
| committer | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2010-10-09 21:20:13 +0200 |
| commit | 69d1615d7dc7500039dbde951fa6cbb920eb99b8 (patch) | |
| tree | 93942d2a2dfe7a3996c3b3d217de0955000daa1d /src/jpeg-utils.cpp | |
| parent | a1e7a92e93e4760863105ae9f61ced93510e8cb2 (diff) | |
| download | cataract-69d1615d7dc7500039dbde951fa6cbb920eb99b8.tar.xz | |
Add support for squared thumbnails
Disabled by default, only very simple center crop implemented.
The SQUARED_SIMPLE_SHAVE_AMOUNT constant may be slightly adjusted
according to future experience. It's a really dumb algorithm which
may not be suitable for every picture.
Looking for a fast and smart algorithm to determine image weight center
and radius, i.e. focus on object of interest. The OpenCV's face recognition
features are worth to test and consider, though I fear the speed issues.
Diffstat (limited to 'src/jpeg-utils.cpp')
| -rw-r--r-- | src/jpeg-utils.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/jpeg-utils.cpp b/src/jpeg-utils.cpp index 3bde7b6..d46e064 100644 --- a/src/jpeg-utils.cpp +++ b/src/jpeg-utils.cpp @@ -231,9 +231,10 @@ free_exif_data (TExifData *data) */ gboolean resize_image (const gchar *src, const gchar *dst, - int size_x, int size_y, - int quality, - gboolean thumbnail) + int size_x, int size_y, + int quality, + gboolean thumbnail, + ThumbnailSquareType squared_thumbnail_type) { #define ThrowWandException(wand) \ { \ @@ -248,14 +249,35 @@ resize_image (const gchar *src, const gchar *dst, MagickBooleanType status; MagickWand *magick_wand; + unsigned long w; + unsigned long h; + unsigned long amount; /* Read an image. */ magick_wand = NewMagickWand(); status = MagickReadImage (magick_wand, src); if (status == MagickFalse) - ThrowWandException (magick_wand); - if (thumbnail) + ThrowWandException (magick_wand); + + /* Process thumbnail if required */ + if (thumbnail) { + switch (squared_thumbnail_type) { + case THUMBNAIL_SQUARE_TYPE_SIMPLE: + w = MagickGetImageWidth (magick_wand); + h = MagickGetImageHeight (magick_wand); + amount = MAX (w, h) * SQUARED_SIMPLE_SHAVE_AMOUNT / 100; + MagickShaveImage (magick_wand, amount, amount); + + w = MagickGetImageWidth (magick_wand); + h = MagickGetImageHeight (magick_wand); + amount = MIN (w, h); + MagickCropImage (magick_wand, amount, amount, (w - amount) / 2, (h - amount) / 2); + break; + default: + break; + } MagickThumbnailImage (magick_wand, size_x, size_y); + } else MagickResizeImage (magick_wand, size_x, size_y, LanczosFilter, 1.0); MagickSetImageCompressionQuality (magick_wand, quality); |
