Firstly, I have a confession to make … I am pretty lazy! Perhaps not Homer Simpson lazy, but it’s something I do aspire to! ;) I take some solace from this quote attributed to Bill Gates:
“I choose a lazy person to do a hard job. Because a lazy person will find an easy way to do it.”
On a recent Xamarin.Forms project I was working on, the focus was a UI/UX refresh with a lot of non-linear lines and shapes. Accordingly, there was the need for a lot of images. The requirement was to support @1x, @2x and @3x resolutions on iOS, and mdpi, hdpi, xhdpi and xxhdpi on Android. So for every image required, there were actually 7 variations of the same image at different resolutions. On top of that, as the project went on sometimes images would need to get updated to get things pixel-perfect, while other times churn would be created as the machinations of the business got involved. This added up to many minutes lost to a tedious, error prone, recurring manual task. The pain of this process was particularly felt with Android, which uses the convention of a separate directory for each resolution.
I already had some PowerShell up my sleeve to mitigate some of the pain, but I decided to polish it up and make it available, for the simple joy of writing and shipping code without bureaucracy if nothing else. And so, the Xamarin Image Importer was born, in the form of a module in the PowerShell Gallery.
This little utility aims to do 2 things only - (1) copy images to the correct location in the file structure required by iOS / Android (2) add them to .csproj files so they will appear in Visual/Xamarin Studio. Many of the variables of the process can be inferred by convention. This worked well for the project I was working on, where the designer on the team would export images from a SVG using Illustrator then dump it into a Dropbox folder. From there, the PowerShell slurps in the images and does the rest.
While I have no immediate need to develop the tool further for myself right now, some potential additions I can imagine include:
Anyway, hope this little tool helps some of you out there. Happy lazy coding!