~ubuntu-branches/ubuntu/wily/kid3/wily

« back to all changes in this revision

Viewing changes to src/qml/script/ResizeAlbumArt.qml

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi
  • Date: 2015-05-12 18:56:41 UTC
  • mfrom: (1.1.19) (2.3.3 sid)
  • Revision ID: package-import@ubuntu.com-20150512185641-hgeys2pingwq9mwn
Tags: 3.2.1-1
* New upstream release.
  - Add new build dependency qt4-dev-tools.
* Uploading to unstable.
* Switch to DEP5 debian/copyright format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * \file ResizeAlbumArt.qml
 
3
 * Resize embedded cover art images which are larger than 500x500 pixels.
 
4
 * The maximum size can be adapted by changing the maxPixels variable.
 
5
 *
 
6
 * \b Project: Kid3
 
7
 * \author Urs Fleisch
 
8
 * \date 28 Feb 2015
 
9
 *
 
10
 * Copyright (C) 2015  Urs Fleisch
 
11
 *
 
12
 * This program is free software; you can redistribute it and/or modify
 
13
 * it under the terms of the GNU Lesser General Public License as published by
 
14
 * the Free Software Foundation; version 3.
 
15
 *
 
16
 * This program is distributed in the hope that it will be useful,
 
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
19
 * GNU Lesser General Public License for more details.
 
20
 *
 
21
 * You should have received a copy of the GNU Lesser General Public License
 
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
23
 */
 
24
 
 
25
import Kid3 1.0
 
26
 
 
27
Kid3Script {
 
28
  onRun: {
 
29
    var maxPixels = 500
 
30
 
 
31
    function doWork() {
 
32
      if (app.selectionInfo.tagFormatV2) {
 
33
        var data = app.getPictureData()
 
34
        if (script.getDataSize(data) !== 0) {
 
35
          var format = "JPG"
 
36
          var img = script.dataToImage(data, format)
 
37
          var imgProps = script.imageProperties(img)
 
38
          if (typeof imgProps.width === "undefined") {
 
39
            format = "PNG"
 
40
            img = script.dataToImage(data, format)
 
41
            imgProps = script.imageProperties(img)
 
42
          }
 
43
          var width = imgProps.width, height = imgProps.height
 
44
          if (width > maxPixels || height > maxPixels) {
 
45
            if (width >= height) {
 
46
              width = maxPixels; height = -1
 
47
            } else {
 
48
              width = -1; height = maxPixels
 
49
            }
 
50
            img = script.scaleImage(img, width, height)
 
51
            imgProps = script.imageProperties(img)
 
52
            data = script.dataFromImage(img, format)
 
53
            if (script.getDataSize(data) !== 0) {
 
54
              app.setPictureData(data)
 
55
              console.log("Resized image to %1x%2 in %3".
 
56
                          arg(imgProps.width).arg(imgProps.height).
 
57
                          arg(app.selectionInfo.fileName))
 
58
            }
 
59
          }
 
60
        }
 
61
      }
 
62
      if (!app.nextFile()) {
 
63
        if (isStandalone()) {
 
64
          // Save the changes if the script is started stand-alone, not from Kid3.
 
65
          app.saveDirectory()
 
66
        }
 
67
        Qt.quit()
 
68
      } else {
 
69
        setTimeout(doWork, 1)
 
70
      }
 
71
    }
 
72
 
 
73
    app.firstFile()
 
74
    doWork()
 
75
  }
 
76
}