Skip to content

Commit

Permalink
feat(mac): resize icons for Linux using sips on macOS to avoid graphi…
Browse files Browse the repository at this point in the history
…csmagick dependency

graphicsmagick is not required anymore. sips is bundled with macOS — no need to install.
  • Loading branch information
develar committed Jun 18, 2017
1 parent f47fd9b commit e5817bc
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 19 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/develar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#osx_image: xcode8.3
osx_image: xcode8.3

matrix:
include:
Expand All @@ -23,12 +23,13 @@ cache:
before_install:
- curl -L https://dl.bintray.com/develar/bin/7za -o /tmp/7za
- chmod +x /tmp/7za
- curl -L https://dl.bintray.com/develar/bin/wine.7z -o /tmp/wine.7z
- curl -L https://dl.bintray.com/develar/bin/wine-2.0.7z -o /tmp/wine.7z
- /tmp/7za x -o/usr/local/Cellar -y /tmp/wine.7z
- brew link --overwrite fontconfig gd gnutls jasper libgphoto2 libicns libtasn1 libusb libusb-compat little-cms2 nettle openssl sane-backends webp wine git-lfs gnu-tar dpkg xz
- brew install freetype graphicsmagick
- brew link --overwrite gnutls libtasn1 libusb libusb-compat nettle openssl wine git-lfs gnu-tar dpkg xz
- git-lfs pull

# fontconfig jasper libgphoto2 libicns little-cms2 sane-backends webp gd

install:
- nvm install $NODE_VERSION
- nvm use --delete-prefix $NODE_VERSION
Expand Down
2 changes: 1 addition & 1 deletion docs/Multi Platform Build.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ brew install mono

### To build app for Linux on macOS:
```
brew install gnu-tar graphicsmagick xz
brew install gnu-tar xz
```

To build rpm: `brew install rpm`.
Expand Down
22 changes: 12 additions & 10 deletions packages/electron-builder/src/targets/LinuxTargetHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { LinuxBuildOptions, LinuxTargetSpecificOptions } from "../options/linuxO

export const installPrefix = "/opt"

/** @private */
export class LinuxTargetHelper {
readonly icons: Promise<Array<Array<string>>>

Expand Down Expand Up @@ -148,13 +147,7 @@ export class LinuxTargetHelper {

function resize(size: number): Promise<any> {
const filename = `icon_${size}x${size}.png`

if (iconFiles.includes(filename)) {
return BluebirdPromise.resolve()
}

const sizeArg = `${size}x${size}`
return exec("gm", ["convert", "-size", sizeArg, imagePath, "-resize", sizeArg, path.join(tempDir, filename)])
return iconFiles.includes(filename) ? BluebirdPromise.resolve() : resizeImage(imagePath, path.join(tempDir, filename), size, size)
}

const promises: Array<Promise<any>> = [resize(24), resize(96)]
Expand All @@ -177,8 +170,7 @@ export class LinuxTargetHelper {
this.maxIconPath = imagePath

function resize(size: number): Promise<any> {
const sizeArg = `${size}x${size}`
return exec("gm", ["convert", "-size", sizeArg, imagePath, "-resize", sizeArg, path.join(tempDir, `icon_${size}x${size}x32.png`)])
return resizeImage(imagePath, path.join(tempDir, `icon_${size}x${size}x32.png`), size, size)
}

const promises: Array<Promise<any>> = [resize(24), resize(96)]
Expand Down Expand Up @@ -220,4 +212,14 @@ export class LinuxTargetHelper {
createMapping("512"),
]
}
}

function resizeImage(imagePath: string, result: string, w: number, h: number) {
if (process.platform === "darwin") {
return exec("sips", ["--resampleHeightWidth", h.toString(10), w.toString(10), imagePath, "--out", result])
}
else {
const sizeArg = `${w}x${h}`
return exec("gm", ["convert", "-size", sizeArg, imagePath, "-resize", sizeArg, result])
}
}
26 changes: 22 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ combined-stream@^1.0.5, combined-stream@~1.0.5:
dependencies:
delayed-stream "~1.0.0"

command-line-args@^4.0.1:
command-line-args@^4.0.1, command-line-args@^4.0.6:
version "4.0.6"
resolved "https://registry.yarnpkg.com/command-line-args/-/command-line-args-4.0.6.tgz#0ff87a1dd159890dcaeb2a005abdae71e55059fc"
dependencies:
Expand Down Expand Up @@ -2853,13 +2853,14 @@ repeating@^2.0.0:
is-finite "^1.0.0"

req-then@^0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/req-then/-/req-then-0.6.1.tgz#e85af6b939ffcc4b4f145b7e51cae73e8f8052c9"
version "0.6.2"
resolved "https://registry.yarnpkg.com/req-then/-/req-then-0.6.2.tgz#7f9e6ebbcab327adc9280aa92b3698d3fc1c5b0d"
dependencies:
array-back "^1.0.4"
defer-promise "^1.0.1"
lodash.pick "^4.4.0"
typical "^2.6.0"
stream-read-all "^0.1.0"
typical "^2.6.1"

request@^2.45.0, request@^2.79.0:
version "2.81.0"
Expand Down Expand Up @@ -3082,6 +3083,12 @@ stream-connect@^1.0.2:
dependencies:
array-back "^1.0.2"

stream-read-all@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/stream-read-all/-/stream-read-all-0.1.0.tgz#04fd4498d4f29717f5b7f316354425cf318c6385"
dependencies:
test-runner "^0.4.0"

stream-via@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/stream-via/-/stream-via-1.0.4.tgz#8dccbb0ac909328eb8bc8e2a4bd3934afdaf606c"
Expand Down Expand Up @@ -3225,6 +3232,17 @@ test-exclude@^4.1.1:
read-pkg-up "^1.0.1"
require-main-filename "^1.0.1"

test-runner@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/test-runner/-/test-runner-0.4.0.tgz#41426f9b3dfff4bcda2cb23f3b7df73d67d6b8a2"
dependencies:
ansi-escape-sequences "^3.0.0"
array-back "^1.0.4"
command-line-args "^4.0.6"
command-line-usage "^4.0.0"
file-set "^1.1.1"
reduce-flatten "^1.0.1"

test-value@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/test-value/-/test-value-1.1.0.tgz#a09136f72ec043d27c893707c2b159bfad7de93f"
Expand Down

0 comments on commit e5817bc

Please sign in to comment.