Last active
August 29, 2015 13:57
-
-
Save itsananderson/9821727 to your computer and use it in GitHub Desktop.
Fetch placeholder images from placekitten.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: | |
# place-kitten.ps1 [-OutputDirectory <directory>] [resolution [...]] | |
# | |
# Examples | |
# place-kitten.ps1 400/300 1200/900 1920/1080 | |
# place-kitten.ps1 -OutputDirectory c:\kitty 400/300 1200/900 | |
Param( | |
[string]$OutputDirectory=$(pwd), | |
[string]$DimensionFile="", | |
[Parameter(Position=0,ValueFromRemainingArguments=$true)] | |
$dimensions | |
) | |
$client = new-object System.Net.WebClient | |
if ( $DimensionFile ) { | |
if ( test-path $DimensionFile ) { | |
$fileLines = Get-Content $DimensionFile | |
$dimensions = $dimensions + $fileLines | |
} else { | |
"Dimension file '$DimensionFile' doesn't exist" | |
exit | |
} | |
} | |
if ( 0 -eq ([Array]$dimensions).Length) { | |
"You must provide at least one image dimension argument" | |
exit | |
} | |
$dimensions | foreach-object { | |
"Downloading http://placekitten.com/$_ to "+$OutputDirectory+"\\"+($_ -Replace "/", "x")+".jpg" | |
$client.DownloadFile( "http://placekitten.com/$_", $OutputDirectory+"\\"+($_ -Replace "/", "x")+".jpg") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment