Commit 3f378601 authored by Maik Qualmann's avatar Maik Qualmann

shorter code for image scaling

parent 42774d6e
Pipeline #26010 failed with stage
in 60 minutes
...@@ -118,45 +118,17 @@ bool ImageResizeJob::imageResize(MailSettings* const settings, ...@@ -118,45 +118,17 @@ bool ImageResizeJob::imageResize(MailSettings* const settings,
img.load(orgUrl.toLocalFile()); img.load(orgUrl.toLocalFile());
} }
uint sizeFactor = settings->imageSize;
if (!img.isNull()) if (!img.isNull())
{ {
uint w = img.width(); uint sizeFactor = settings->imageSize;
uint h = img.height();
if ((w > sizeFactor) || (h > sizeFactor)) if ((img.width() > sizeFactor) || (img.height() > sizeFactor))
{ {
if (w > h) DImg scaledImg = img.smoothScale(sizeFactor,
{ sizeFactor,
h = (uint)((double)(h * sizeFactor) / w); Qt::KeepAspectRatio);
if (h == 0)
{
h = 1;
}
w = sizeFactor;
Q_ASSERT(h <= sizeFactor);
}
else
{
w = (uint)((double)(w * sizeFactor) / h);
if (w == 0)
{
w = 1;
}
h = sizeFactor;
Q_ASSERT(w <= sizeFactor);
}
DImg scaledImg = img.smoothScale(w, h, Qt::IgnoreAspectRatio);
if ((scaledImg.width() != w) || (scaledImg.height() != h)) if ((scaledImg.width() > sizeFactor) || (scaledImg.height() > sizeFactor))
{ {
err = i18n("Cannot resize image. Aborting."); err = i18n("Cannot resize image. Aborting.");
return false; return false;
......
...@@ -180,45 +180,17 @@ bool FCTask::imageResize(const QString& orgUrl, const QString& destName, QString ...@@ -180,45 +180,17 @@ bool FCTask::imageResize(const QString& orgUrl, const QString& destName, QString
img.load(orgUrl); img.load(orgUrl);
} }
uint sizeFactor = d->settings.imageResize;
if (!img.isNull()) if (!img.isNull())
{ {
uint w = img.width(); uint sizeFactor = d->settings.imageResize;
uint h = img.height();
if ((w > sizeFactor) || (h > sizeFactor)) if ((img.width() > sizeFactor) || (img.height() > sizeFactor))
{ {
if (w > h) DImg scaledImg = img.smoothScale(sizeFactor,
{ sizeFactor,
h = (uint)((double)(h * sizeFactor) / w); Qt::KeepAspectRatio);
if (h == 0)
{
h = 1;
}
w = sizeFactor;
Q_ASSERT(h <= sizeFactor);
}
else
{
w = (uint)((double)(w * sizeFactor) / h);
if (w == 0)
{
w = 1;
}
h = sizeFactor;
Q_ASSERT(w <= sizeFactor);
}
DImg scaledImg = img.smoothScale(w, h, Qt::IgnoreAspectRatio);
if ((scaledImg.width() != w) || (scaledImg.height() != h)) if ((scaledImg.width() > sizeFactor) || (scaledImg.height() > sizeFactor))
{ {
err = i18n("Cannot resize image. Aborting."); err = i18n("Cannot resize image. Aborting.");
return false; return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment