Instantly share code, notes, and snippets.

What would you like to do?
Windows Powershell Script to download the latest image from the Himawari-8 satelite, combine the tiles into a single image, convert to jpg and then set as the desktop background.
# Himawari-8 Downloader
# This script will scrape the latest image from the Himawari-8 satellite, recombining the tiled image,
# converting it to a JPG which is saved in My Pictures\Himawari\ and then set as the desktop background.
$ts = New-TimeSpan -Hours -2 -Minutes -30 #Number of hours and minutes to add/subtract to the date. Adjust this to offset your system date to around about GMT (I think?)
$now = ((Get-Date -Second 00) + $ts)
$now = $now.AddMinutes(-($now.minute % 10))
$width = 550
$level = "4d" #Level can be 4d, 8d, 16d, 20d
$numblocks = 4 #this apparently corresponds directly with the level, keep this exactly the same as level without the 'd'
$time = $now.ToString("HHmmss")
$year = $now.ToString("yyyy")
$month = $now.ToString("MM")
$day = $now.ToString("dd")
#Create the folder My Pictures\Himawari\ if it doesnt exist
$outpath = [Environment]::GetFolderPath("MyPictures") + "\Himawari\"
if(!(Test-Path -Path $outpath ))
[void](New-Item -ItemType directory -Path $outpath)
#The filename that will be saved:
#Uncomment this to have the files accumulate in the directory:
#$outfile = "$year$month$day"+"_" + $time + ".jpg"
#Use this to have the script just store the latest file only:
$outfile = "latest.jpg"
$url = "$level/$width/$year/$month/$day/$time"
$image = New-Object System.Drawing.Bitmap(($width * $numblocks), ($width * $numblocks))
$graphics = [System.Drawing.Graphics]::FromImage($image)
for ($y = 0; $y -lt $numblocks; $y++)
for ($x = 0; $x -lt $numblocks; $x++)
$thisurl = $url + "_" + [String]$x + "_" + [String]$y + ".png"
Write-Output "Downloading: $thisurl"
$request = [System.Net.WebRequest]::create($thisurl)
$response = $request.getResponse()
$HTTP_Status = [int]$response.StatusCode
If ($HTTP_Status -eq 200)
$imgblock = [System.Drawing.Image]::fromStream($response.getResponseStream())
$graphics.DrawImage($imgblock,($x*$width),($y*$width) , $width, $width)
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
Write-Output "Failed! $ErrorMessage with $FailedItem"
$qualityEncoder = [System.Drawing.Imaging.Encoder]::Quality
$encoderParams = New-Object System.Drawing.Imaging.EncoderParameters(1)
# Set JPEG quality level here: 0 - 100 (inclusive bounds)
$encoderParams.Param[0] = New-Object System.Drawing.Imaging.EncoderParameter($qualityEncoder, 90)
$jpegCodecInfo = [System.Drawing.Imaging.ImageCodecInfo]::GetImageEncoders() | where {$_.MimeType -eq 'image/jpeg'}
$$outpath + $outfile), $jpegCodecInfo, $encoderParams)
Different settings for the wallpaper:
Tile :
key.SetValue(@"WallpaperStyle", "0") ;
key.SetValue(@"TileWallpaper", "1") ;
Center :
key.SetValue(@"WallpaperStyle", "0") ;
key.SetValue(@"TileWallpaper", "0") ;
Stretch :
key.SetValue(@"WallpaperStyle", "2") ;
key.SetValue(@"TileWallpaper", "0") ;
Fill :
key.SetValue(@"WallpaperStyle", "10") ;
key.SetValue(@"TileWallpaper", "0") ;
Fit :
key.SetValue(@"WallpaperStyle", "6") ;
key.SetValue(@"TileWallpaper", "0") ;
Write-Output "Setting Wallpaper..."
Set-ItemProperty -path "HKCU:Control Panel\Desktop" -name Wallpaper -value ($outpath + $outfile)
Set-ItemProperty -path "HKCU:Control Panel\Desktop" -name WallpaperStyle -value 6
Set-ItemProperty -path "HKCU:Control Panel\Desktop" -name TileWallpaper -value 0
Set-ItemProperty 'HKCU:\Control Panel\Colors' -name Background -Value "0 0 0"
#rundll32.exe user32.dll, UpdatePerUserSystemParameters
$setwallpapersource = @"
using System.Runtime.InteropServices;
public class wallpaper
public const int SetDesktopWallpaper = 20;
public const int UpdateIniFile = 0x01;
public const int SendWinIniChange = 0x02;
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern int SystemParametersInfo (int uAction, int uParam, string lpvParam, int fuWinIni);
public static void SetWallpaper ( string path )
SystemParametersInfo( SetDesktopWallpaper, 0, path, UpdateIniFile | SendWinIniChange );
Add-Type -TypeDefinition $setwallpapersource
[wallpaper]::SetWallpaper(($outpath + $outfile))
Write-Output "Done"

This comment has been minimized.

jakiestfu commented Feb 4, 2016



This comment has been minimized.

jbolster commented Feb 4, 2016

Nice one :) I've made a slight change - there is a URL that provides the latest image details ( I pull the date stamp from this and instead of using the current time (at the point I tried your script, it was just 'No Image' images being returned).


This comment has been minimized.

xmichaelx commented Feb 4, 2016

$ts = New-TimeSpan -Hours -2 -Minutes -30

You're GMT+2h30min?


This comment has been minimized.

godofgrunts commented Feb 4, 2016

$numblocks = $level -replace '\D' #automatically removes the 'd'

This will eliminate the user having to manually fix that.


This comment has been minimized.

MangoTwo2 commented Feb 4, 2016

GMT -2:30 is that Azores?


This comment has been minimized.

jakiestfu commented Feb 6, 2016

I created an NPM module for downloading images from the Himawari satellite. I used your code as inspiration and credited you in the readme. I also added support for @jbolster's solution for latest images.


This comment has been minimized.

lhmiranda commented Feb 11, 2016

Created a Windows Tray Application inspired by your code.


This comment has been minimized.

kevinhughes27 commented Feb 22, 2016

I had to add:


to get this to work (windows 10)


This comment has been minimized.

bjavman commented Feb 23, 2016

For those in EST, change the timespan to +5 hours and -30 minutes. You can see if it matches the real-time image here:


This comment has been minimized.

ClumsyPenguin commented Nov 9, 2016

how do i prevent that powershell keep popping up while he is downloading the tiles ?


This comment has been minimized.

vortex456 commented Jul 10, 2017

i can set it as a wallpaper but it won't rejenerate in 10 min

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment