Commit 7b928f3b authored by Laurent Montel's avatar Laurent Montel 😁

Fix Bug 349180 - resizing attached images corrupts the images

BUG: 349180
FIXED-IN: 4.14.10
Now we don't change image format if not necessary
parent b9d88a5f
......@@ -510,6 +510,7 @@ void Composer::addAttachmentPart( AttachmentPart::Ptr part, bool autoresizeImage
if (MessageComposer::Utils::resizeImage(part)) {
MessageComposer::ImageScaling autoResizeJob;
autoResizeJob.setName(part->name());
autoResizeJob.setMimetype(part->mimeType());
if(autoResizeJob.loadImageFromData(part->data())) {
if(autoResizeJob.resizeImage()) {
part->setData(autoResizeJob.imageArray());
......
......@@ -91,7 +91,16 @@ bool ImageScaling::resizeImage()
if ((newHeight != height) || (newWidth != width)) {
mBuffer.open(QIODevice::WriteOnly);
mImage = mImage.scaled(newWidth,newHeight, MessageComposer::MessageComposerSettings::self()->keepImageRatio() ? Qt::KeepAspectRatio : Qt::IgnoreAspectRatio);
const bool result = mImage.save(&mBuffer,MessageComposer::MessageComposerSettings::self()->writeFormat().toLocal8Bit());
QByteArray format;
if (mMimeType == "image/jpeg") {
format = "JPG";
} else if (mMimeType == "image/png") {
format = "PNG";
} else {
format = MessageComposer::MessageComposerSettings::self()->writeFormat().toLocal8Bit();
}
const bool result = mImage.save(&mBuffer, format);
mBuffer.close();
return result;
} else {
......@@ -103,16 +112,25 @@ bool ImageScaling::resizeImage()
QByteArray ImageScaling::mimetype() const
{
//Add more mimetype if a day we add more saving format.
const QString type = MessageComposer::MessageComposerSettings::self()->writeFormat();
if (type == QLatin1String("JPG")) {
return "image/jpeg";
} else if (type == QLatin1String("PNG")) {
return "image/png";
if ((mMimeType == "image/jpeg") || (mMimeType == "image/png")) {
return mMimeType;
} else {
//Add more mimetype if a day we add more saving format.
const QString type = MessageComposer::MessageComposerSettings::self()->writeFormat();
if (type == QLatin1String("JPG")) {
return "image/jpeg";
} else if (type == QLatin1String("PNG")) {
return "image/png";
}
}
return QByteArray();
}
void ImageScaling::setMimetype(const QByteArray &mimetype)
{
mMimeType = mimetype;
}
void ImageScaling::setName(const QString &name)
{
mName = name;
......@@ -125,6 +143,10 @@ QByteArray ImageScaling::imageArray() const
QString ImageScaling::generateNewName()
{
// Don't rename it.
if ((mMimeType == "image/jpeg") || (mMimeType == "image/png")) {
return mName;
}
const QString type = MessageComposer::MessageComposerSettings::self()->writeFormat();
if (mName.endsWith(QLatin1String(".png"))) {
if (type != QLatin1String("PNG")) {
......
......@@ -52,6 +52,7 @@ public:
* @return new image mimetype after saving.
*/
QByteArray mimetype() const;
void setMimetype(const QByteArray &mimetype);
void setName(const QString &name);
......@@ -60,6 +61,7 @@ private:
QImage mImage;
QBuffer mBuffer;
QString mName;
QByteArray mMimeType;
};
}
......
......@@ -47,7 +47,7 @@
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Write to format</string>
<string>Fallback to format:</string>
</property>
</widget>
</item>
......
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