Skip to content

Instantly share code, notes, and snippets.

@jagedn
Last active April 4, 2020 08:45
Show Gist options
  • Save jagedn/8d7244d0595a27001b2c37fceb631be9 to your computer and use it in GitHub Desktop.
Save jagedn/8d7244d0595a27001b2c37fceb631be9 to your computer and use it in GitHub Desktop.
Download Picture of the Day from NASA and add the explanation
import javax.imageio.ImageIO
json = new groovy.json.JsonSlurper().parse("https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY".toURL())
url = json.url
ext = url.split('\\.').last().toLowerCase()
if( ['jpg','png','jpeg'].contains(ext) == false ){
return
}
image = ImageIO.read(url.toURL())
g = image.graphics
g.font = g.font.deriveFont(25f)
lines = json.explanation.take(300).split("(?<=\\G.{100})")+["","Made with \u2665 by Puravida Software"]
lines.eachWithIndex{ str, idx ->
g.drawString str, 20, 20+(idx*30)
}
g.dispose()
ImageIO.write(image, "jpg", new File("${System.getProperty("user.home")}/Pictures/nasa.jpg"))
@jagedn
Copy link
Author

jagedn commented Apr 4, 2020

I have this script in a crontab every 12h to refresh my desktop banckground
But most time I was curious about the picture, so I added the explanation in the top corner

example:
nasa

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