Warning, /multimedia/kid3/src/qml/script/ResizeAlbumArt.qml is written in an unsupported language. File is not indexed.
0001 /**
0002 * \file ResizeAlbumArt.qml
0003 * Resize embedded cover art images which are larger than 500x500 pixels.
0004 * The maximum size can be adapted by changing the maxPixels variable.
0005 *
0006 * \b Project: Kid3
0007 * \author Urs Fleisch
0008 * \date 28 Feb 2015
0009 *
0010 * Copyright (C) 2015-2017 Urs Fleisch
0011 *
0012 * This program is free software; you can redistribute it and/or modify
0013 * it under the terms of the GNU Lesser General Public License as published by
0014 * the Free Software Foundation; version 3.
0015 *
0016 * This program is distributed in the hope that it will be useful,
0017 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0019 * GNU Lesser General Public License for more details.
0020 *
0021 * You should have received a copy of the GNU Lesser General Public License
0022 * along with this program. If not, see <http://www.gnu.org/licenses/>.
0023 */
0024
0025 import Kid3 1.1
0026
0027 Kid3Script {
0028 onRun: {
0029 var maxPixels = 500
0030
0031 function doWork() {
0032 if (app.selectionInfo.tag(Frame.Tag_2).tagFormat) {
0033 var data = app.getPictureData()
0034 if (script.getDataSize(data) !== 0) {
0035 var formats = ["jpg", "png", "webp"]
0036 for (var fmt in formats) {
0037 var format = formats[fmt]
0038 var img = script.dataToImage(data, format)
0039 var imgProps = script.imageProperties(img)
0040 if ("width" in imgProps) {
0041 var width = imgProps.width, height = imgProps.height
0042 if (width > maxPixels || height > maxPixels) {
0043 if (width >= height) {
0044 width = maxPixels; height = -1
0045 } else {
0046 width = -1; height = maxPixels
0047 }
0048 img = script.scaleImage(img, width, height)
0049 imgProps = script.imageProperties(img)
0050 data = script.dataFromImage(img, format)
0051 if (script.getDataSize(data) !== 0) {
0052 app.setPictureData(data)
0053 console.log("Resized image to %1x%2 in %3".
0054 arg(imgProps.width).arg(imgProps.height).
0055 arg(app.selectionInfo.fileName))
0056 }
0057 }
0058 break
0059 }
0060 }
0061 }
0062 }
0063 if (!nextFile()) {
0064 if (isStandalone()) {
0065 // Save the changes if the script is started stand-alone, not from Kid3.
0066 app.saveDirectory()
0067 }
0068 Qt.quit()
0069 } else {
0070 setTimeout(doWork, 1)
0071 }
0072 }
0073
0074 firstFile()
0075 doWork()
0076 }
0077 }