asset_opt 🎯

A powerful Flutter/Dart tool for analyzing and optimizing project assets. Get detailed insights into your asset usage and automatically optimize images to improve your app's performance.

Repo Card

Features πŸš€

Detailed Asset Analysis

  • πŸ“Š Size and type distribution visualization
  • πŸ“ Directory structure breakdown
  • πŸ” Image dimension analysis
  • ⚠️ Issue detection and recommendations

Smart Optimization

  • πŸ—œοΈ Automatic image compression
  • πŸ“ Size reduction while maintaining quality
  • πŸ”„ Format conversion suggestions
  • πŸ’Ύ Safe backups before optimization

Beautiful Reports

  • πŸ“ˆ Visual progress tracking
  • 🎨 Color-coded terminal output
  • πŸ“‹ Detailed JSON reports
  • πŸ“Š Size statistics and savings

Installation πŸ“₯

dart pub global activate asset_opt

Or add to your pubspec.yaml for project-specific usage:

dev_dependencies:
  asset_opt: ^1.0.2

Usage πŸ’»

Command Line

# Show help and available commands
asset_opt --help

# Analyze project assets
asset_opt --analyze

# Analyze and optimize
asset_opt --optimize

# Specify project path and quality
asset_opt -p /path/to/project -q 85 --optimize

# Verbose output
asset_opt --verbose

As a Library

import 'package:asset_opt/asset_opt.dart';

void main() async {
  // Initialize services
  final fileService = FileService();
  final imageService = ImageService();
  final analysisState = AnalysisState();

  // Create analyzer
  final analyzer = AnalyzeCommand(
    fileService,
    imageService,
    analysisState,
  );

  // Run analysis
  final analysis = await analyzer.execute('./');

  // Check for issues
  if (analysis.hasIssues()) {
    print('Found optimization opportunities:');
    for (final asset in analysis.assets) {
      if (asset.issues.isNotEmpty) {
        print('${asset.info.name}:');
        for (final issue in asset.issues) {
          print('  - ${issue.message}');
        }
      }
    }
  }
}

Output Examples πŸ“Έ

Asset Analysis

πŸ“Š Asset Analysis Report
────────────────────────
Project: /Users/username/projects/my_app
────────────────────────
└─ assets (632 files, 22.4 MB)
   β”œβ”€ images (631 files, 22.4 MB)
   β”‚  β”œβ”€ flags (492 files, 3.7 MB)
   β”‚  └─ bgs (4 files, 2.5 MB)
   └─ icons (1 files, 829 B)

Type Distribution

πŸ—‚  Assets by Type
────────────────────────
Type     Size       Files   Distribution
PNG      22.4 MB    631    β”‚β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  β”‚ 65.2%
JPEG     10.2 MB    492    β”‚β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ              β”‚ 29.8%
WEBP      1.5 MB      4    β”‚β–ˆβ–ˆβ–ˆ                           β”‚  4.3%
SVG     829.0 B       1    β”‚                              β”‚  0.7%

Optimization Suggestions

⚠️  Optimization Opportunities
────────────────────────
❌ background.png
   Current: 2.5 MB
   Recommended: < 500 KB (reduce by 80%)
   β†’ Use pngquant or tinypng for lossless compression

Configuration βš™οΈ

Create asset_opt.yaml in your project root:

# Asset optimization settings
optimization:
  jpeg_quality: 85
  webp_quality: 80
  strip_metadata: true

# Size limits
limits:
  max_file_size: 1MB
  max_total_size: 50MB

# Patterns to exclude
exclude:
  - '**/test/assets/*'

FAQ ❓

Q: Is it safe to use on production assets? A: Yes! The tool creates backups before any optimization.

Q: What image formats are supported? A: Currently supports PNG, JPEG, WebP, and SVG files.

Q: Will this work with my CI/CD pipeline? A: Yes, the tool can be integrated into CI/CD workflows.

Contributing 🀝

Contributions are welcome! Please read our contributing guidelines before submitting pull requests.

Roadmap πŸ—ΊοΈ

Version 1.2.0

  • Configuration file support
  • Custom optimization presets
  • Watch mode for development

Version 1.3.0

  • WebP conversion
  • SVG optimization
  • Asset usage analysis

License πŸ“„

Licensed under the MIT License file for details.

Support πŸ’ͺ

If you find this tool helpful, please consider:

  • Starring the repository ⭐
  • Reporting issues πŸ›
  • Contributing to the code πŸ’»
  • Sharing with others 🌟