From cd37dc9ed94f0fa8738396c9a18a0c398f52694c Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Sat, 30 Oct 2010 13:05:15 +0200 Subject: Don't resize an image if it fits in desired size --- src/jpeg-utils.cpp | 39 ++++++++++++++++++++++----------------- src/jpeg-utils.h | 2 +- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/jpeg-utils.cpp b/src/jpeg-utils.cpp index a63afdd..3ec547c 100644 --- a/src/jpeg-utils.cpp +++ b/src/jpeg-utils.cpp @@ -231,7 +231,7 @@ free_exif_data (TExifData *data) */ gboolean resize_image (const gchar *src, const gchar *dst, - int size_x, int size_y, + unsigned long size_x, unsigned long size_y, int quality, gboolean thumbnail, ThumbnailSquareType squared_thumbnail_type) @@ -259,23 +259,28 @@ resize_image (const gchar *src, const gchar *dst, if (status == MagickFalse) 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; - amount = MIN (w - 2*amount, h - 2*amount); - MagickCropImage (magick_wand, amount, amount, (w - amount) / 2, (h - amount) / 2); - break; - default: - break; - } - MagickThumbnailImage (magick_wand, size_x, size_y); + + /* Don't resize if smaller than desired size */ + if (MagickGetImageWidth (magick_wand) > size_x || MagickGetImageHeight (magick_wand) > size_y) { + /* 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; + amount = MIN (w - 2*amount, h - 2*amount); + 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); } - else - MagickResizeImage (magick_wand, size_x, size_y, LanczosFilter, 1.0); + MagickSetImageCompressionQuality (magick_wand, quality); /* Write the image and destroy it. */ diff --git a/src/jpeg-utils.h b/src/jpeg-utils.h index e31ed52..e26218e 100644 --- a/src/jpeg-utils.h +++ b/src/jpeg-utils.h @@ -69,7 +69,7 @@ void free_exif_data (TExifData *data); * - setting thumbnail flag will remove all profiles and optimize for size */ gboolean resize_image (const gchar *src, const gchar *dst, - int size_x, int size_y, + unsigned long size_x, unsigned long size_y, int quality, gboolean thumbnail, ThumbnailSquareType squared_thumbnail_type); -- cgit v1.2.3