import fs from 'fs' ; import path from 'path' ; import probeImageSize from 'probe-image-size' ; import { ExponentTools , LoggerDetach } from '../internal' ; param { string } projectDirname param { string } basename returns { } async function getImageDimensionsAsync ( projectDirname , basename ) { try { return await _getImageDimensionsAsync ( projectDirname , basename ) ; } catch { } return null ; } async function _getImageDimensionsWithImageProbeAsync ( projectDirname , basename ) { const imagePath = path . resolve ( projectDirname , basename ) ; const readStream = fs . createReadStream ( imagePath ) ; const { width , height } = await probeImageSize ( readStream ) ; readStream . destroy ( ) ; return { width , height } ; } let _hasWarned = false ; async function resizeImageAsync ( iconSizePx , iconFilename , destinationIconPath ) { if ( process . platform !== 'darwin' && _resizeImageAsync === _resizeImageWithSipsAsync && ! _hasWarned ) { 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 ExponentTools . spawnAsyncThrowError ( 'sips' , [ '-Z' , iconSizePx . toFixed ( ) , iconFilename ] , { stdio : [ 'ignore' , 'ignore' , 'inherit' ] , cwd : destinationIconPath } ) ; } let _resizeImageAsync = _resizeImageWithSipsAsync ; let _getImageDimensionsAsync = _getImageDimensionsWithImageProbeAsync ; function setResizeImageFunction ( fn ) { _resizeImageAsync = fn ; } function setGetImageDimensionsFunction ( fn ) { _getImageDimensionsAsync = fn ; } export { resizeImageAsync , setResizeImageFunction , setGetImageDimensionsFunction , getImageDimensionsAsync , } ;