added auto-chose of image format if there is no transparency

This commit is contained in:
csoler 2023-01-16 21:24:16 +01:00
parent 516e4f7c12
commit de1b8f08d2

View File

@ -145,7 +145,19 @@ bool ImageUtil::optimizeSizeHtml(QString &html, const QImage& original, QImage &
if(maxBytes < 1) maxBytes = 1; if(maxBytes < 1) maxBytes = 1;
} }
if(optimizeSizeBytes(bytearray, original, optimized,"PNG",maxPixels, maxBytes)) // check for transparency
bool has_transparency = false;
if(original.hasAlphaChannel())
for(int i=0;i<original.width();++i)
for(int j=0;j<original.height();++j)
if(qAlpha(original.pixel(i,j)) < 255)
{
has_transparency = true;
break;
}
if(optimizeSizeBytes(bytearray, original, optimized,has_transparency?"PNG":"JPG",maxPixels, maxBytes))
{ {
QByteArray encodedByteArray = bytearray.toBase64(); QByteArray encodedByteArray = bytearray.toBase64();
html = "<img src=\"data:image/png;base64,"; html = "<img src=\"data:image/png;base64,";