updateTiles static method

Future<String> updateTiles(
  1. String folder,
  2. String oldFile,
  3. String newFile,
  4. bool puzzle,
)

Обновление тайлов

Implementation

static Future<String> updateTiles(
  String folder,
  String oldFile,
  String newFile,
  bool puzzle,
) async {
  await deleteTiles(folder, oldFile);

  final tempDir = await tempFolder;
  final name = newFile.split('/').last.split('.').first;
  final ext = getFileExt(newFile);
  final scales = puzzle ? puzzleScales : comicsScales;

  // Получаем размеры исходного изображения
  final size = await ImageProcessor.getImageSize(newFile);

  // Создаем тайлы для каждого масштаба
  for (final scale in scales) {
    final scaleInt = (scale * 1000).round();
    final scaledWidth = (size.width * scale).round();
    final scaledHeight = (size.height * scale).round();

    final scaledPath = '$tempDir/$folder/${name}_$scaleInt$ext';
    final tileTemplate =
        '$tempDir/$folder/${name}_${scaleInt}_{0}_{1}_{2}$ext';

    // Изменяем размер изображения
    await ImageProcessor.resizeImage(
      newFile,
      scaledPath,
      scaledWidth,
      scaledHeight,
    );

    // Создаем тайлы
    await ImageProcessor.createTiles(scaledPath, tileTemplate, tileSize);

    // Удаляем промежуточный файл
    await File(scaledPath).delete();
  }

  // Создаем placeholder для puzzle режима
  if (puzzle) {
    final placeholderPath = '$tempDir/$folder/${name}_ph_0_0$ext';
    if (size.width > placeholderSize || size.height > placeholderSize) {
      await ImageProcessor.createPlaceholder(
        newFile,
        placeholderPath,
        placeholderSize,
      );
    } else {
      await File(newFile).copy(placeholderPath);
    }
  }

  final fullName = '${name}_{0}_{1}_{2}$ext';
  return fullName;
}