Home

Awesome

DEPRECATED: Check out Resizetizer NT and the blog post about it!

Resizetizer DEPRECATED

NuGet

Have you ever wanted an easier way to manage all those different sizes of images in your app? Resizetizer is a more sane way to automate this process, and is friendly to developers who suck at design (like myself!).

You an use SVG vectors or PNG/BMP/JPG graphics as source assets, and with a bit of simple configuration, have them automatically resized to every resolution your app needs!

Easy Installation

  1. Add the Resizetizer NuGet package to one of your projects.
  2. Create a resizetizer.yaml configuration file in your project with your assets and output ratio/files you want.
  3. Set the build action of your resizetizer.yaml file to ResizetizerConfig.
  4. Build your project and watch the magic!

How does it work?

Resizetizer itself is a simple library for resizing SVG or PNG (and more in the future) source assets to various size ratio outputs (fully customizable).

The Resizetizer NuGet package contains a custom MSBuild task which will run before the PrepareForBuild target in the project you add it to when you compile.

The MSBuild task will look for YAML or JSON config files with a build action of ResizetizerConfig to figure out what images to resize, and how to resize them.

A Resizetizer.stamps file is created in your project's immediates output directory after assets are resized with modify timestamps from the source asset file listed for each output to ensure assets aren't resized unless the source has actually changed. If you find any issues with this, just delete this file and rebuild.

Configuring Resizetizer

Your config file should look something like this:

- platform: Android
  outputBasePath: "./MyProj.Droid/Resources/"
  assets:
   - file: "../input/happy.svg"
     size: 100x100
  outputs:
   - path: "./drawable-mdpi"
     ratio: 1.0
   - path: "./drawable-hdpi"
     ratio: 1.5
   - path: "./drawable-xhdpi"
     ratio: 2.0
   - path: "./drawable-xxhdpi"
     ratio: 3.0
   - path: "./drawable-xxxhdpi"
     ratio: 4.0
- platform: iOS
  outputBasePath: "./MyProj.iOS/Images/"
  assets:
   - file: "../input/happy.svg"
     size: 36x36
  outputs:
   - ratio: 1.0
   - fileSuffix: "@2x"
     ratio: 2.0
   - fileSuffix: "@3x"
     ratio: 3.0

As you can see above, you can specify multiple configurations in a single file (you could have multiple files if you wish too!). Each configuration requires an outputBasePath to be declared, which is relative to the location of the config file itself.

Optimization

PNG Output Optimization will be enabled by default. You can disable it by setting optimize: false on the config, or on an individual output item.

For now, optimization is a no-op. I am looking at different options to run optimizations on.

You can run your own optimization tool of choice by using the External Commands for the time being.

External Commands

It's possible to specify external commands to run on the config or an individual output item. You can use the following tags which will be substituted for you in your commands:

Here's an example:

- platform: iOS
  outputBasePath: "./MyProj.iOS/Images/"
  externalCommands:
   - /usr/local/bin/optipng -o7 "{outputFile}"
  assets:
   - file: "../input/happy.svg"
     size: 36x36
  outputs:
   - ratio: 1.0

SVG Fill Color

You can also change The fill color of an SVG on your output specification. For example:

- platform: iOS
  outputBasePath: "./MyProj.iOS/Images/"
  assets:
   - file: "../input/happy.svg"
     size: 36x36
  outputs:
   - ratio: 1.0
     fillColor: #000000
   - fileSuffix: "@2x"
     ratio: 2.0
     fillColor: #000000

This will change every path in the source SVG to be black (#000000) in the resulting output file. This only works for SVG assets.

Configuration Reference

What's next?

Automatically add generated assets to Xamarin.iOS and Xamarin.Android projects

Currently Resizetizer does not automatically add resized assets to your app projects (e.g.: it will not add images inside a drawable-hdpi folder to your Xamarin.Android app project). You will still have to manually add them as references in your projects the after first time they are generated. One idea is to have this all automated for Xamarin.Android and Xamarin.iOS projects.

PDF Asset support

It's somewhat common for iOS developers to use PDF files in their projects. It would be nice for Resizetizer to support this format... However it should. More research needed.