Skip to content

Instantly share code, notes, and snippets.

@Serivy
Created January 24, 2018 05:52
Show Gist options
  • Save Serivy/f607b008f4309915b024e6676c369822 to your computer and use it in GitHub Desktop.
Save Serivy/f607b008f4309915b024e6676c369822 to your computer and use it in GitHub Desktop.
Generates Cordova resources from 2 base images.
Add-Type -AssemblyName System.Drawing
function Process
{
Param($In, $OutFile, $Square, $W, $H, $BG, $ResizeW)
$file = Get-Item $In
$img = [System.Drawing.Image]::FromFile($file)
# Set the target image size
$destWidth = $img.Width;
$destHeight = $img.Height;
if ($Square) {
$destWidth = $Square;
$destHeight = $Square;
}
if ($W) {
$destWidth = $W
$destHeight = $H
}
# Figure out where to draw the image
$drawArea = New-Object System.Drawing.Rectangle(0, 0, $destWidth, $destHeight)
if ($ResizeW) {
$drawArea.Width = $ResizeW
$drawArea.Height = ($ResizeW / $($img.Width)) * $($img.Height)
$drawArea.Y = $destHeight / 2 - $drawArea.Height / 2
$drawArea.X = $destWidth / 2 - $drawArea.Width / 2
}
$out = New-Object System.Drawing.Bitmap($destWidth, $destHeight, "Format32bppPArgb");
$g = [System.Drawing.Graphics]::FromImage($out)
$g.InterpolationMode = "HighQualityBicubic";
if ($BG) {
$color = [System.Drawing.ColorTranslator]::FromHtml($BG);
$g.Clear($color)
}
$g.DrawImage($img, $drawArea)
$out.Save($OutFile, "Png");
$img.Dispose()
}
Process "icon.png" "icons\android\icon-36-ldpi.png" -Square 36
Process "icon.png" "icons\android\icon-48-mdpi.png" -Square 48
Process "icon.png" "icons\android\icon-72-hdpi.png" -Square 72
Process "icon.png" "icons\android\icon-96-xhdpi.png" -Square 96
Process "icon.png" "icons\ios\icon-40.png" -Square 40
Process "icon.png" "icons\ios\icon-40-2x.png" -Square 80
Process "icon.png" "icons\ios\icon-50.png" -Square 50
Process "icon.png" "icons\ios\icon-50-2x.png"-Square 100
Process "icon.png" "icons\ios\icon-57.png" -Square 57 -BG "#A4A4A4" -ResizeW 50
Process "icon.png" "icons\ios\icon-57-2x.png" -Square 144 -BG "#A4A4A4" -ResizeW 110
Process "icon.png" "icons\ios\icon-60.png" -Square 60
Process "icon.png" "icons\ios\icon-60-2x.png" -Square 120
Process "icon.png" "icons\ios\icon-60-3x.png" -Square 180
Process "icon.png" "icons\ios\icon-72.png" -Square 72 -BG "#A4A4A4" -ResizeW 60
Process "icon.png" "icons\ios\icon-72-2x.png" -Square 144 -BG "#A4A4A4" -ResizeW 132
Process "icon.png" "icons\ios\icon-76.png" -Square 76 -ResizeW 65
Process "icon.png" "icons\ios\icon-76-2x.png" -Square 152 -ResizeW 140
Process "icon.png" "icons\ios\icon-small.png" -Square 29
Process "icon.png" "icons\ios\icon-small-2x.png" -Square 58
Process "icon.png" "icons\windows\Square30x30Logo.scale-100.png" -Square 30 -ResizeW 20 -BG "#464646"
Process "icon.png" "icons\windows\Square44x44Logo.scale-100.png" -Square 44
Process "icon.png" "icons\windows\Square44x44Logo.scale-240.png" -Square 106
Process "icon.png" "icons\windows\Square70x70Logo.scale-100.png" -Square 70 -ResizeW 60 -BG "#464646"
Process "icon.png" "icons\windows\Square71x71Logo.scale-100.png" -Square 71
Process "icon.png" "icons\windows\Square71x71Logo.scale-240.png" -Square 170
Process "icon.png" "icons\windows\Square150x150Logo.scale-100.png" -Square 150 -ResizeW 100 -BG "#464646"
Process "icon.png" "icons\windows\Square150x150Logo.scale-240.png" -Square 360
Process "icon.png" "icons\windows\Square310x310Logo.scale-100.png" -Square 310 -ResizeW 300 -BG "#464646"
Process "icon.png" "icons\windows\StoreLogo.scale-100" -Square 50 -ResizeW 30 -BG "#464646"
Process "icon.png" "icons\windows\StoreLogo.scale-240.png" -Square 120
Process "icon.png" "icons\windows\Wide310x150Logo.scale-100.png" -W 310 -H 150 -ResizeW 100
Process "icon.png" "icons\windows\Wide310x150Logo.scale-240.png" -W 744 -H 360 -ResizeW 300
Process "logo.png" "screens\android\screen-hdpi-landscape.png" -W 640 -H 480 -ResizeW 290 -BG "#33393D"
Process "logo.png" "screens\android\screen-hdpi-portrait.png" -W 480 -H 640 -ResizeW 290 -BG "#33393D"
Process "logo.png" "screens\android\screen-ldpi-landscape.png" -W 426 -H 320 -ResizeW 200 -BG "#33393D"
Process "logo.png" "screens\android\screen-ldpi-portrait.png" -W 320 -H 426 -ResizeW 200 -BG "#33393D"
Process "logo.png" "screens\android\screen-mdpi-landscape.png" -W 470 -H 320 -ResizeW 150 -BG "#33393D"
Process "logo.png" "screens\android\screen-mdpi-portrait.png" -W 320 -H 470 -ResizeW 150 -BG "#33393D"
Process "logo.png" "screens\android\screen-xhdpi-landscape.png" -W 960 -H 720 -ResizeW 400 -BG "#33393D"
Process "logo.png" "screens\android\screen-xhdpi-portrait.png" -W 720 -H 960 -ResizeW 400 -BG "#33393D"
Process "logo.png" "screens\ios\screen-ipad-landscape.png" -W 1024 -H 768 -ResizeW 600 -BG "#33393D"
Process "logo.png" "screens\ios\screen-ipad-landscape-2x.png" -W 2048 -H 1536 -ResizeW 1300 -BG "#33393D"
Process "logo.png" "screens\ios\screen-ipad-portrait.png" -W 768 -H 1024 -ResizeW 500 -BG "#33393D"
Process "logo.png" "screens\ios\screen-ipad-portrait-2x.png" -W 1536 -H 2048 -ResizeW 1000 -BG "#33393D"
Process "logo.png" "screens\ios\screen-iphone-568h-2x.png" -W 640 -H 1136 -ResizeW 400 -BG "#33393D"
Process "logo.png" "screens\ios\screen-iphone-landscape-736h.png" -W 2208 -H 1242 -ResizeW 1800 -BG "#33393D"
Process "logo.png" "screens\ios\screen-iphone-portrait.png" -W 320 -H 480 -ResizeW 200 -BG "#33393D"
Process "logo.png" "screens\ios\screen-iphone-portrait-2x.png" -W 640 -H 960 -ResizeW 500 -BG "#33393D"
Process "logo.png" "screens\ios\screen-iphone-portrait-667h.png" -W 750 -H 1334 -ResizeW 600 -BG "#33393D"
Process "logo.png" "screens\ios\screen-iphone-portrait-736h.png" -W 1242 -H 2208 -ResizeW 1000 -BG "#33393D"
Process "logo.png" "screens\windows\SplashScreen.scale-100.png" -W 620 -H 300 -ResizeW 400 -BG "#464646"
Process "logo.png" "screens\windows\SplashScreen.scale-240.png" -W 1152 -H 1920 -ResizeW 600
Process "logo.png" "screens\windows\SplashScreenPhone.scale-240.png" -W 1152 -H 1920 -ResizeW 600
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment