Skip to content

Commit c8dc50c

Browse files
committed
Merge branch 'main' into fix-notebook
2 parents ec43bfe + 65e9271 commit c8dc50c

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

deps.edn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
com.illposed.osc/javaosc-core {:mvn/version "0.8" :exclusions [org.slf4j/slf4j-api org.slf4j/slf4j-log4j12]}
2828

2929
org.babashka/cli {:mvn/version "0.7.52"}
30+
org.babashka/http-client {:mvn/version "0.4.23"}
3031

3132
;; silence log warnings
3233
org.slf4j/slf4j-nop {:mvn/version "1.7.36"}}

notebooks/images.clj

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
^{:nextjournal.clerk/visibility #{:hide-ns}}
33
(ns images
44
(:require [nextjournal.clerk :as clerk]
5-
[clojure.java.io :as io])
5+
[clojure.java.io :as io]
6+
[babashka.http-client :as http])
67
(:import [java.net URL]
78
[java.nio.file Paths Files]
89
[java.awt.image BufferedImage]
@@ -17,10 +18,14 @@
1718
;; `java.io.InputStream`, or any resource that a `java.net.URL` can
1819
;; address.
1920

20-
;; For example, we can fetch a photo of _De zaaier_, Vincent van
21-
;; Gogh's famous painting of a farmer sowing a field from Wiki
22-
;; Commons like this:
23-
(ImageIO/read (URL. "https://upload.wikimedia.org/wikipedia/commons/thumb/3/31/The_Sower.jpg/1510px-The_Sower.jpg"))
21+
;; For example, we can fetch a photo of _De zaaier_, Vincent van Gogh's famous
22+
;; painting of a farmer sowing a field from Wiki Commons like this. Since Wiki
23+
;; Commons requires a User-Agent header to be set when requesting the image, we
24+
;; use babashka.http-client.
25+
(ImageIO/read
26+
(-> (http/get "https://upload.wikimedia.org/wikipedia/commons/thumb/3/31/The_Sower.jpg/1510px-The_Sower.jpg"
27+
{:as :stream})
28+
:body))
2429

2530
;; We've put some effort into making the default image rendering
2631
;; pleasing. The viewer uses the dimensions and aspect ratio of each

0 commit comments

Comments
 (0)