imageSizeFtn method

  1. @defineMethodSkip
ImageDimension imageSizeFtn (
  1. Quoted filePathNode
)

Implementation

@defineMethodSkip
ImageDimension imageSizeFtn(Quoted filePathNode) {
  var filePath = filePathNode.value;
  final currentDirectory =
      currentFileInfo.rewriteUrls > RewriteUrlsConstants.off
          ? currentFileInfo.currentDirectory
          : currentFileInfo.entryPath;

  final fragmentStart = filePath.indexOf('#');
  if (fragmentStart != -1) {
    filePath = filePath.substring(0, fragmentStart);
  }

  final fileManager = environment.getFileManager(
      filePath, currentDirectory, context, environment,
      isSync: true);
  final fileSync =
      fileManager.existSync(filePath, currentDirectory, context, environment);
  if (fileSync.error != null) {
    throw fileSync.error;
  }

  return imageSizeProcessor.sizeOf(fileSync.filename);

// 3.7.1 20180718
//  function imageSize(functionContext, filePathNode) {
//      var filePath = filePathNode.value;
//      var currentFileInfo = functionContext.currentFileInfo;
//      var currentDirectory = currentFileInfo.rewriteUrls ?
//      currentFileInfo.currentDirectory : currentFileInfo.entryPath;
//
//      var fragmentStart = filePath.indexOf('#');
//      var fragment = '';
//      if (fragmentStart !== -1) {
//          fragment = filePath.slice(fragmentStart);
//          filePath = filePath.slice(0, fragmentStart);
//      }
//
//      var fileManager = environment.getFileManager(filePath, currentDirectory, functionContext.context, environment, true);
//
//      if (!fileManager) {
//          throw {
//              type: 'File',
//              message: 'Can not set up FileManager for ' + filePathNode
//          };
//      }
//
//      var fileSync = fileManager.loadFileSync(filePath, currentDirectory, functionContext.context, environment);
//
//      if (fileSync.error) {
//          throw fileSync.error;
//      }
//
//      var sizeOf = require('image-size');
//      return sizeOf(fileSync.filename);
//  }
}