Skip to content

Instantly share code, notes, and snippets.

@itsananderson
Last active August 29, 2015 13:57
Show Gist options
  • Save itsananderson/9821727 to your computer and use it in GitHub Desktop.
Save itsananderson/9821727 to your computer and use it in GitHub Desktop.
Fetch placeholder images from placekitten.com
# 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