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,
img.load(orgUrl.toLocalFile());
}
uint sizeFactor = settings->imageSize;
if (!img.isNull())
{
uint w = img.width();
uint h = img.height();
uint sizeFactor = settings->imageSize;
if ((w > sizeFactor) || (h > sizeFactor))
if ((img.width() > sizeFactor) || (img.height() > sizeFactor))
{
if (w > h)
{
h = (uint)((double)(h * sizeFactor) / w);
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);
DImg scaledImg = img.smoothScale(sizeFactor,
sizeFactor,
Qt::KeepAspectRatio);
if ((scaledImg.width() != w) || (scaledImg.height() != h))
if ((scaledImg.width() > sizeFactor) || (scaledImg.height() > sizeFactor))
{
err = i18n("Cannot resize image. Aborting.");
return false;
......
......@@ -180,45 +180,17 @@ bool FCTask::imageResize(const QString& orgUrl, const QString& destName, QString
img.load(orgUrl);
}
uint sizeFactor = d->settings.imageResize;
if (!img.isNull())
{
uint w = img.width();
uint h = img.height();
uint sizeFactor = d->settings.imageResize;
if ((w > sizeFactor) || (h > sizeFactor))
if ((img.width() > sizeFactor) || (img.height() > sizeFactor))
{
if (w > h)
{
h = (uint)((double)(h * sizeFactor) / w);
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);
DImg scaledImg = img.smoothScale(sizeFactor,
sizeFactor,
Qt::KeepAspectRatio);
if ((scaledImg.width() != w) || (scaledImg.height() != h))
if ((scaledImg.width() > sizeFactor) || (scaledImg.height() > sizeFactor))
{
err = i18n("Cannot resize image. Aborting.");
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