Request inline images in the right size and anti-alias them
- If an inline image has specified a height, add parameters to the image:// URI. - Add scaled to the parameters, the images would be cropped otherwise. - Extract the height from image:// URI and use it for requestSize. - Use scaledToHeight instead of scaled.
This commit is contained in:
parent
7742f12f30
commit
7086e23bdd
2 changed files with 39 additions and 9 deletions
|
|
@ -27,6 +27,7 @@ MxcImageProvider::requestImageResponse(const QString &id, const QSize &requested
|
|||
auto id_ = id;
|
||||
bool crop = true;
|
||||
double radius = 0;
|
||||
auto size = requestedSize;
|
||||
|
||||
auto queryStart = id.lastIndexOf('?');
|
||||
if (queryStart != -1) {
|
||||
|
|
@ -39,11 +40,14 @@ MxcImageProvider::requestImageResponse(const QString &id, const QSize &requested
|
|||
crop = false;
|
||||
} else if (b.startsWith("radius=")) {
|
||||
radius = b.mid(7).toDouble();
|
||||
} else if (b.startsWith("height=")) {
|
||||
size.setHeight(b.mid(7).toInt());
|
||||
size.setWidth(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new MxcImageResponse(id_, crop, radius, requestedSize);
|
||||
return new MxcImageResponse(id_, crop, radius, size);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -120,7 +124,9 @@ MxcImageProvider::download(const QString &id,
|
|||
if (fileInfo.exists()) {
|
||||
QImage image = utils::readImageFromFile(fileInfo.absoluteFilePath());
|
||||
if (!image.isNull()) {
|
||||
image = image.scaled(requestedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
if (requestedSize != image.size()) {
|
||||
image = image.scaledToHeight(requestedSize.height(), Qt::SmoothTransformation);
|
||||
}
|
||||
|
||||
if (radius != 0) {
|
||||
image = clipRadius(std::move(image), radius);
|
||||
|
|
@ -151,8 +157,10 @@ MxcImageProvider::download(const QString &id,
|
|||
auto data = QByteArray(res.data(), (int)res.size());
|
||||
QImage image = utils::readImage(data);
|
||||
if (!image.isNull()) {
|
||||
image =
|
||||
image.scaled(requestedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
if (requestedSize != image.size()) {
|
||||
image =
|
||||
image.scaledToHeight(requestedSize.height(), Qt::SmoothTransformation);
|
||||
}
|
||||
|
||||
if (radius != 0) {
|
||||
image = clipRadius(std::move(image), radius);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue