Skip to content

Commit

Permalink
Fix path to cwebp on Apple Silicon Macs (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
subdan authored Jan 12, 2022
1 parent b9919a2 commit 625f76a
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions Sources/FigmaExport/Output/WebpConverter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,27 @@ final class WebpConverter {
func convert(file url: URL) throws {
let outputURL = url.deletingPathExtension().appendingPathExtension("webp")

var executableURLs = [
URL(fileURLWithPath: "/usr/local/bin/cwebp"),
URL(fileURLWithPath: "/opt/homebrew/bin/cwebp")
]

let task = Process()
task.executableURL = URL(fileURLWithPath: "/usr/local/bin/cwebp")
if case Encoding.lossless = encoding {
task.arguments = ["-lossless", url.path, "-o", outputURL.path, "-short"]
} else if case Encoding.lossy(let quality) = encoding {
task.arguments = ["-q", String(quality), url.path, "-o", outputURL.path, "-short"]
}
try task.run()
task.waitUntilExit()

repeat {
task.executableURL = executableURLs.removeFirst()
do {
try task.run()
task.waitUntilExit()
return
} catch {
continue
}
} while !executableURLs.isEmpty
}
}

0 comments on commit 625f76a

Please sign in to comment.