MCPcopy Create free account
hub / github.com/Martchus/tageditor / convertImage

Method convertImage

cli/scriptapi.cpp:238–261  ·  view source on GitHub ↗

! * \brief Resizes an image converting it to the specified \a format using the specified \a quality. * \returns Returns the converted image or in case the conversion is not possible the original \a imageData. * \remarks * - In case \a maxSize is zero the original size will be kept. In this case the conversion to the specified * \a format with the specified \a quality will always be done. *

Source from the content-addressed store, hash-verified

236 * to true.
237 */
238QByteArray UtilityObject::convertImage(const QByteArray &imageData, const QSize &maxSize, const QString &format, int quality, bool force)
239{
240 auto image = QImage::fromData(imageData);
241 auto imageChanged = false;
242 if (image.isNull()) {
243 return imageData;
244 }
245 if (maxSize.isNull()) {
246 imageChanged = true;
247 } else if (image.width() > maxSize.width() || image.height() > maxSize.height()) {
248 image = image.scaled(maxSize.width(), maxSize.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
249 imageChanged = true;
250 if (image.isNull()) {
251 return imageData;
252 }
253 }
254 if (!imageChanged && !force) {
255 return imageData;
256 }
257 auto newData = QByteArray();
258 auto buffer = QBuffer(&newData);
259 auto res = buffer.open(QIODevice::WriteOnly) && image.save(&buffer, format.isEmpty() ? "JPEG" : format.toUtf8().data(), quality);
260 return res ? newData : imageData;
261}
262
263static QString propertyString(const QJSValue &obj, const QString &propertyName)
264{

Callers 3

mainFunction · 0.80
addCoverFunction · 0.80
queryCoverFromProviderFunction · 0.80

Calls 1

dataMethod · 0.45

Tested by

no test coverage detected