... in pure Powershell -- for free (registration, but no moneys)
- You get 5k of image generations with z-image and others, when you register for free.
https://enter.pollinations.ai/
PollinationsAI-Img -?
PollinationsAI-Img [-content] <string> [-settings <hashtable>] [-model <string>] [-POLLINATIONSAI_API_KEY <string>]
PollinationsAI-Img [-content] <string> -details [-settings <hashtable>] [-model <string>] [-POLLINATIONSAI_API_KEY <string>]
PollinationsAI-Img [-content] <string> -save [-settings <hashtable>] [-model <string>] [-POLLINATIONSAI_API_KEY <string>]
PollinationsAI-Img [-content] <string> -out <string> [-settings <hashtable>] [-model <string>] [-POLLINATIONSAI_API_KEY <string>]
PollinationsAI-Img -listModels [-details]
PollinationsAI-Img -getSettingsDefaultYes: Optional <CommonParameters> is always supported.
Note
➡️ Interchangeably use PollinationsAI-Img for .\ask.pollinations_image.ps1 in this documentation. Exact same params apply.
⭐ PollinationsAI-Img can be used globally, using the file itself works only where it is saved.
In your Powershell prompt, paste the following to download the comandlet into the Powershell profile folder and activate it:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://gist.githubusercontent.com/BananaAcid/6bc2fc33d948d28d255674a7613f120c/raw/integrate.ps1'))only download it into your current folder
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; Invoke-WebRequest 'https://gist.githubusercontent.com/BananaAcid/6bc2fc33d948d28d255674a7613f120c/raw/ask.pollinations_image.ps1' -out 'ask.pollinations_image.ps1';| arg | default | example | desc |
|---|---|---|---|
<string> or -content <string> or -prompt <string> |
(required) | "Some Text-Prompt" |
The content to be created. |
-model <string> |
"zimage" |
"flux" |
The model to use. |
-POLLINATIONSAI_API_KEY <string> or -key <string> |
$env:POLLINATIONSAI_API_KEY |
sk_12345678901234567890 |
Use a PollonationsAI API Key - if left set to "", $env:POLLINATIONSAI_API_KEY is being checked. Note: Add the API key to your environment variables. |
-settings <hashtable> |
see below | @{seed = 1234567890} |
A hashtable of settings passed to the Pollinations AI API. |
-out <string> |
acat.jpg |
The local path to save the generated image and returns the path. | |
-save |
Will save to the system temp folder and returns the path. | ||
-details |
Does not save the image and returns @{ Headers; Content } |
||
-getSettingsDefault or -get |
Get the default settings for the PollinationsAI API. | ||
-listModels or -list |
Outputs a table of models, that are currently available on PollinationsAI. | ||
-listModels -details or -list -details |
Outputs a Hashtable of models, to be used in code. |
Important
Returns:
- Default: The generated image as a byte array
-details: The headers as and content as a byte array@{ Headers; Content }-save: The local path to generated file-out <name.jpg>: The local path to generated file
Caution
on error:
- throws
@{ StatusCode = <error code>; Message = <error message> }
Note
You can always shorten a param (to use -c or -con instead of -content)
Make it available to your shell as a function (if you did not do the "quickly integrate it") ... for local use
Function PollinationsAI-Img { & <absolutepath>\ask.pollinations_image.ps1 @args }Doing this, you can use PollinationsAI-Img -listModels in any folder (while in the same session), instead of .\ask.pollinations_image.ps1 -listModels within the script folder only.
To make it always available in a powershell session, add it a file shown with $Profile | Select-Object * (CurrentUserAllHosts is a good place).
PollinationsAI-Img "a cat" -save
# C:\Users\<username>\AppData\Local\Temp\00974dda-c60c-4c4f-b6bc-4c6e948616d5.jpg-Debug shows the used URL and the local file path of the generated image.
PollinationsAI-Img "a cat" -save -Debug | Invoke-Item
# DEBUG: URI: https://gen.pollinations.ai/image/a%20cat?model=zimage
# DEBUG: Filepath: C:\Users\<username>\AppData\Local\Temp\00974dda-c60c-4c4f-b6bc-4c6e948616d5.jpgGenerate an image based on the prompt "a cat" using the flux model and save it into the local folder as acat.jpg
PollinationsAI-Img -content "a cat" -model flux -out acat
# acat.jpgif .jpg (or .png) is missing, it will be added (depending on the model).
$c = "England"; PollinationsAI-Img "for $c, show the country flag in 3D in the shape of that country with a slight shadow ### DO NOT SHOW ANY PEOPLE" -out .\country_$c
# country_England.jpgPS> $env:POLLINATIONSAI_API_KEY = "sk_..."
PS> $s = PollinationsAI-Img -getSettingsDefault # or: PollinationsAI-Img -get
PS> $s
Name Value
---- -----
safe false
image
enhance false
negative_prompt worst quality, blurry
transparent false
quality medium
width 1024
height 1024
seed 0
PS> $s.width = 512
PS> $s.height = 512
PS> PollinationsAI-Img -content "a cat" -settings $s -out acat.jpg- First set the API key,
- then get the default settings,
- then output the settings (just by typing $s),
- then modify them,
- then generate an image based on the prompt "a cat" using the modified settings.
$result = PollinationsAI-Img "a cat"
$imgTag = "<center><img src=`"data:image/jpg;base64,{0}`" /></center>" -f [convert]::ToBase64String($result.Content)
$imgTag | Out-File -FilePath test-img.html -Encoding utf8
start test-img.html$models = PollinationsAI-Img -list -Details |% {$_.name}
$models |% { PollinationsAI-Img "a cat" -model $_ -out imgs\cat_$_.jpg }
# imgs\cat_kontext.jpg
# imgs\cat_turbo.jpg
# ...-
Get the
Set-Wallpapercommandlet (choose the updated version) from here: https://www.joseespitia.com/2017/09/15/set-wallpaper-powershell-function/- save it as
set-wallpaper.ps1 ⚠️ but DO NOT include the last line that saysSet-WallPaper -Image "C:\Wallpaper\Background.jpg" -Style Fit
- save it as
-
Your script
update.wallpaper.ps1- Prerequisites:
- Function
PollinationsAI-Imgis set (see above), otherwise replace its occurence with.\ask.pollinations_image.ps1 $env:POLLINATIONSAI_API_KEY = "sk_..."is set
- Function
param ([switch]$Test, [string]$Color) $colors = @("green", "blue", "black", "white", "orange", "purple") $model = "seedream" # according to `.\ask.pollinations_image.ps1 -List` it supports image input. 1 Pollen == 33 images (0.03P) $color = $color ? $color : (Get-Random $colors) Write-Output "Setting wallpaper to $color" # only generate if it does not exist, for speed (reduces unnecessary calls and `seadream` takes its time) if (-not (Test-path ".\wp_$color.jpg")) { Write-Output "Generating new image ..." # this might return a cached instance from PollinationsAI without any cost $newImage = PollinationsAI-Img ` -Content "change the logo to be in $color with tint in $color" ` -Settings @{image = "https://upload.wikimedia.org/wikipedia/en/thumb/8/80/Wikipedia-logo-v2.svg/960px-Wikipedia-logo-v2.svg.png"} ` -Model $model ` -Out ".\wp_$color.jpg" } else { $newImage = ".\wp_$color.jpg" } Write-Output "New image: $newImage" # if -Test was used, do not continue if ($Test) { return } # import the Set-Wallpaper function . .\set-wallpaper.ps1 # set the new wallpaper Set-Wallpaper -Image $newImage -Style Center
Logo Reference https://en.wikipedia.org/wiki/File:Wikipedia-logo-v2.svg
- Prerequisites:
Note
You can test it with (without actually changing the wallpaper):
.\update.wallpaper.ps1 -Test
.\update.wallpaper.ps1 -Test -Color red And to test changing the wallpaper:
.\update.wallpaper.ps1 # random color
.\update.wallpaper.ps1 -Color red # specifically red color-
Use Windows Task Scheduler to set the script to be repeated and be started on system start ...
example code to manually add it
⚠️ You need to changepwsh.exeintopowershell.exein the script, if you do not have Powershell 6+ installed.# Define the script path and name for the task $scriptPath = "C:\Scripts\update.wallpaper.ps1" # Replace with the actual path to your .ps1 file $taskName = "ChangeWallpaperHourlyAtLogon" $taskDescription = "Runs update.wallpaper.ps1 every hour after user login" # Define the action (start powershell.exe with arguments) $action = New-ScheduledTaskAction -Execute "pwsh.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File $scriptPath" # Define the trigger (at logon, repeating every hour indefinitely) # The -AtLogOn trigger doesn't directly support RepetitionInterval in one line # We must use a workaround by setting the Repetition properties after creating the task $trigger = New-ScheduledTaskTrigger -AtLogOn # Define the principal (runs as the current user when logged in) $principal = New-ScheduledTaskPrincipal -UserId "$env:USERDOMAIN\$env:USERNAME" -LogonType Interactive # Register the initial task (without the repetition settings configured directly) Register-ScheduledTask -TaskName $taskName -Description $taskDescription -Action $action -Trigger $trigger -Principal $principal -Force | Out-Null # Retrieve the newly created task object to modify its repetition settings $task = Get-ScheduledTask -TaskName $taskName # Set the repetition interval and duration $task.Triggers.Repetition.Interval = (New-TimeSpan -Hours 1) $task.Triggers.Repetition.Duration = ([System.TimeSpan]::MaxValue) # Indefinite duration # Update the task with the modified trigger settings $task | Set-ScheduledTask
License: MIT