"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getImageDimensionsAsync = getImageDimensionsAsync; exports.resizeImageAsync = resizeImageAsync; exports.setGetImageDimensionsFunction = setGetImageDimensionsFunction; exports.setResizeImageFunction = setResizeImageFunction; function _fs() { const data = _interopRequireDefault(require("fs")); _fs = function () { return data; }; return data; } function _path() { const data = _interopRequireDefault(require("path")); _path = function () { return data; }; return data; } function _probeImageSize() { const data = _interopRequireDefault(require("probe-image-size")); _probeImageSize = function () { return data; }; return data; } function _internal() { const data = require("../internal"); _internal = function () { return data; }; return data; } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * @param {string} projectDirname * @param {string} basename * @returns {} { width: number, height: number } image dimensions or null */ async function getImageDimensionsAsync(projectDirname, basename) { try { return await _getImageDimensionsAsync(projectDirname, basename); } catch {} return null; } async function _getImageDimensionsWithImageProbeAsync(projectDirname, basename) { const imagePath = _path().default.resolve(projectDirname, basename); const readStream = _fs().default.createReadStream(imagePath); const { width, height } = await (0, _probeImageSize().default)(readStream); readStream.destroy(); return { width, height }; } let _hasWarned = false; async function resizeImageAsync(iconSizePx, iconFilename, destinationIconPath) { if (process.platform !== 'darwin' && _resizeImageAsync === _resizeImageWithSipsAsync && !_hasWarned) { _internal().LoggerDetach.warn('`sips` utility may or may not work outside of macOS'); _hasWarned = true; } return _resizeImageAsync(iconSizePx, iconFilename, destinationIconPath); } async function _resizeImageWithSipsAsync(iconSizePx, iconFilename, destinationIconPath) { return _internal().ExponentTools.spawnAsyncThrowError('sips', ['-Z', iconSizePx.toFixed(), iconFilename], { stdio: ['ignore', 'ignore', 'inherit'], // only stderr cwd: destinationIconPath }); } // Allow us to swap out the default implementations of image functions let _resizeImageAsync = _resizeImageWithSipsAsync; let _getImageDimensionsAsync = _getImageDimensionsWithImageProbeAsync; // Allow users to provide an alternate implementation for our image resize function. // This is used internally in order to use sharp instead of sips in standalone builder. function setResizeImageFunction(fn) { _resizeImageAsync = fn; } // Allow users to provide an alternate implementation for our image dimensions function. // This is used internally in order to use sharp instead of sips in standalone builder. function setGetImageDimensionsFunction(fn) { _getImageDimensionsAsync = fn; } //# sourceMappingURL=ImageUtils.js.map