Skip to content

Commit

Permalink
[imageplugin] Fix MIME media type
Browse files Browse the repository at this point in the history
1. The file extension might not be the correct MIME type, and is empty
   for images extracted from the clipboard
2. The image is converted to a JPEG, anyway
  • Loading branch information
FlorianFieber committed Jun 19, 2014
1 parent 402c7b0 commit fe9d9d1
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions generic/imageplugin/imageplugin.cpp
Expand Up @@ -267,11 +267,12 @@ void ImagePlugin::actionActivated()
}

QByteArray image;
QString mimeType("jpeg");
if(pix.height() > MAX_SIZE || pix.width() > MAX_SIZE) {
pix = pix.scaled(MAX_SIZE, MAX_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation);
}
QBuffer b(&image);
pix.save(&b, "jpg");
pix.save(&b, mimeType.toAscii().constData());
QString imageBase64(QUrl::toPercentEncoding(image.toBase64()));
int length = image.length();
if(length > 61440) {
Expand All @@ -290,13 +291,13 @@ void ImagePlugin::actionActivated()
.arg(jidToSend)
.arg(stanzaSender->uniqueId(account))
.arg(body)
.arg(fileName.right(fileName.length() - fileName.lastIndexOf(".") - 1))
.arg(mimeType)
.arg(imageBase64);

stanzaSender->sendStanza(account, msgHtml);
psiController->appendSysMsg(account, jidToSend, tr("Image %1 sent <br/><img src=\"data:image/%2;base64,%3\" alt=\"img\"/> ")
.arg(imageName)
.arg(fileName.right(fileName.length() - fileName.lastIndexOf(".") - 1))
.arg(mimeType)
.arg(imageBase64));


Expand Down

0 comments on commit fe9d9d1

Please sign in to comment.