Skip to content

Export XKCDTerminalImage

AzureDevOps edited this page Oct 6, 2026 · 6 revisions

Export-XKCDTerminalImage

SYNOPSIS

Renders a comic using the current terminal's inline image graphics protocol (Sixel, Kitty, or iTerm2) and saves the result to a file, so it can be redisplayed later with Import-XKCDTerminalImage.

SYNTAX

Export-XKCDTerminalImage [[-Number] <Int32[]>] [-HighQuality] [-Path <String>] [-PassThru] [-Force] [-Offline]
 [-CachePath <String>] [-DownloadPath <String>] [-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm]
 [<CommonParameters>]

DESCRIPTION

The Export-XKCDTerminalImage cmdlet gets a comic and renders it exactly as Show-XKCD would -- using whichever inline graphics protocol your terminal supports -- but instead of writing the result to the console, it saves it to a file. That file can later be redisplayed instantly with Import-XKCDTerminalImage or Show-XKCD -Path, without needing network access or having to regenerate the image data again (which for Sixel in particular can take a while for large images).

The saved file includes every field returned by Get-XKCD for the comic (num, title, alt, img, and so on), alongside the rendered image, so it can also be used as a self-contained, offline copy of the comic's full details.

Because the saved file contains a protocol-specific escape sequence, it's only guaranteed to display correctly again in a terminal that supports the same graphics protocol it was exported with. The saved file records which protocol that was, and Import-XKCDTerminalImage and Show-XKCD -Path warn you if it doesn't match the protocol detected for the terminal you're importing it into.

By default, Export-XKCDTerminalImage exports the latest available comic. When you use the -Number parameter (aliased as -Num) you can specify one or more specific comics to export.

Use -Offline to get comic data from the local cache (created/refreshed by Update-XKCDCache) and render the comic's image from a copy previously saved with Get-XKCD -Download, instead of fetching either from the xkcd API -- this also governs which comic -Offline considers "latest" when -Number isn't specified. If the comic's image hasn't been downloaded to -DownloadPath yet, a warning is shown asking you to use -Download first, and that comic is skipped. Defaults to the value saved with Set-XKCDDefault -Offline, if any.

EXAMPLES

EXAMPLE 1

Export-XKCDTerminalImage

Exports the latest comic to the current working directory, e.g. as '.\2000.xkcdterm.json'.

EXAMPLE 2

Export-XKCDTerminalImage -Number 353 -Path C:\XKCD

Exports comic number 353 to C:\XKCD, as 'C:\XKCD\353.xkcdterm.json'.

EXAMPLE 3

Get-XKCD -Newest 5 | Export-XKCDTerminalImage -Path C:\XKCD

Exports the 5 most recent comics to C:\XKCD.

EXAMPLE 4

Export-XKCDTerminalImage -Number 353 -PassThru | Import-XKCDTerminalImage

Exports comic number 353 and immediately redisplays it from the saved file.

EXAMPLE 5

Export-XKCDTerminalImage -Number 353 -Force

Re-exports comic number 353, overwriting '.\353.xkcdterm.json' if it already exists. Without -Force, Export-XKCDTerminalImage throws rather than overwrite an existing file.

EXAMPLE 6

Export-XKCDTerminalImage -Number 353 -Offline -DownloadPath C:\XKCD

Exports comic number 353 using its data from the local cache and its image from a copy previously saved to C:\XKCD with Get-XKCD -Download -Path C:\XKCD, without contacting the xkcd API.

PARAMETERS

-Number

Exports the specified comics. Accepts array input. By default the latest comic is exported.

Type: Int32[]
Parameter Sets: (All)
Aliases: Num

Required: False
Position: 1
Default value: None
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False

-HighQuality

Renders the higher resolution (_2x) version of the image, where available. Comics that do not have a higher resolution version are rendered at the standard quality instead. Defaults to the value saved with Set-XKCDDefault -HighQuality, if any.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: (Get-XKCDDefaultValue -Name 'HighQuality' -Value $false)
Accept pipeline input: False
Accept wildcard characters: False

-Path

The local directory to save the exported file(s) to. Each comic is saved as '<num>.xkcdterm.json'. By default this is the current working directory, unless a default has been saved with Set-XKCDDefault -Path.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: (Get-XKCDDefaultValue -Name 'Path' -Value $PWD)
Accept pipeline input: False
Accept wildcard characters: False

-PassThru

Returns a FileInfo object for each file saved, e.g. so it can be piped directly into Import-XKCDTerminalImage.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-Force

Overwrites the destination file if it already exists. Without -Force, Export-XKCDTerminalImage throws rather than overwrite an existing export.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-Offline

Gets comic data from the local cache, and renders the comic's image from a copy previously saved with Get-XKCD -Download, instead of fetching either from the xkcd API. Warns and skips the comic if its image hasn't been downloaded to -DownloadPath yet. Defaults to the value saved with Set-XKCDDefault -Offline, if any.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: (Get-XKCDDefaultValue -Name 'Offline' -Value $false)
Accept pipeline input: False
Accept wildcard characters: False

-CachePath

Use with -Offline to specify where comic data is cached. By default this is within the module path, unless a default has been saved with Set-XKCDDefault -CachePath.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: (Get-XKCDDefaultValue -Name 'CachePath' -Value (Join-Path $PSScriptRoot 'XKCD.json'))
Accept pipeline input: False
Accept wildcard characters: False

-DownloadPath

Use with -Offline to specify the local directory to look for previously downloaded comic images in (as saved by Get-XKCD -Download). By default this is the current working directory, unless a default has been saved with Set-XKCDDefault -Path.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: (Get-XKCDDefaultValue -Name 'Path' -Value $PWD)
Accept pipeline input: False
Accept wildcard characters: False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ProgressAction

{{Fill ProgressAction Description}}

Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).

INPUTS

OUTPUTS

NOTES

RELATED LINKS

https://github.com/markwragg/Powershell-XKCD/wiki/Export-XKCDTerminalImage

https://xkcd.com/json.html

Clone this wiki locally