You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/howto/images.md
+59-29Lines changed: 59 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,18 +7,18 @@ DocTestSetup = quote
7
7
8
8
## Loading and placing images on drawings
9
9
10
-
Luxor lets you place existing images on the drawing. First, load the image:
10
+
Luxor lets you place existing images on the drawing. You can place PNG, SVG, and EPS images. (JPEGs aren't supported.)
11
11
12
-
- for PNG images, use `readpng(filename)`
13
-
- for SVG images, use `readsvg(filename)` or `readsvg(string)`
14
-
- for EPS images, use `placeeps(filename)`
12
+
For PNG and SVG, first load the image and create a reference to it. For example:
15
13
16
-
(JPEGs aren't supported.)
14
+
- for PNG images, use `img = readpng(filename)`
15
+
- for SVG images, use `img = readsvg(filename)` or `img = readsvg(string)`
17
16
18
-
Then use [`placeimage`](@ref) to place the image by its top
19
-
left corner at point `pt`, or use the `centered=true`
20
-
keyword to place the image's center point there. Access the
21
-
image's dimensions with `.width` and `.height`.
17
+
You can access this image's dimensions with `img.width` and `img.height`.
18
+
19
+
Use [`placeimage(img)`](@ref) to place the image by its top
20
+
left corner at point `pt`. Use the `centered=true`
21
+
keyword to place the image's center point there.
22
22
23
23
```@example
24
24
using Luxor # hide
@@ -39,17 +39,23 @@ nothing # hide
39
39
```
40
40

41
41
42
-
PNG images can be placed with varying opacity or transparency.
42
+
PNG images can be placed with varying opacity or transparency. For example, the image is placed with 0.5 opacity with:
43
+
44
+
```julia
45
+
placeimage(img, Point(100, 100), 0.5)
46
+
```
47
+
48
+
SVG images do their own thing in terms of opacity.
43
49
44
50
[`readsvg`](@ref) also lets you supply raw (or pure) SVG code in a string.
45
51
46
-
You can also use `placeimage()` to place an array of RGB or RGBA pixels on a drawing.
52
+
You can use `placeimage()` to place an array of RGB or RGBA pixels on a drawing.
47
53
48
54
```@example
49
55
using Luxor, Colors # hide
50
56
N = 500
51
57
i = reshape([RGBA(rand(4)...) for p in 1:N^2], N, N)
52
-
# is is Matrix{RGBA{Float64}}
58
+
# i is Matrix{RGBA{Float64}}
53
59
# (alias for Array{RGBA{Float64}, 2})
54
60
@draw begin
55
61
origin()
@@ -59,7 +65,7 @@ i = reshape([RGBA(rand(4)...) for p in 1:N^2], N, N)
59
65
end 500 500
60
66
```
61
67
62
-
Or load an image as an array and place it on a drawing.
68
+
Or you can load an image as an array and place it on a drawing.
63
69
64
70
```julia
65
71
using Luxor, Colors, FileIO
@@ -75,10 +81,10 @@ end 250 250
75
81
76
82
## SVG images
77
83
78
-
To create an SVG image, using the `Drawing(... :svg)` or specify an SVG filename.
79
-
To obtain the SVG source of a completed drawing, use [`svgstring`](@ref).
84
+
To output a drawing as an SVG image, using the `Drawing(... :svg)` or specify an SVG filename.
85
+
To obtain the SVG source of a _completed_ SVG drawing, use [`svgstring`](@ref).
80
86
81
-
For example, draw the Julia logo:
87
+
For example, if you draw the Julia logo like this:
82
88
83
89
```julia
84
90
Drawing(500, 500, :svg)
@@ -88,7 +94,7 @@ finish()
88
94
s =svgstring()
89
95
```
90
96
91
-
The SVG source code is now stored in `s`. You can examine or process it further:
97
+
You'll get the SVG source code stored, as a string, in `s`. You can examine or process it further. For example, the five colors used for the logo were:
92
98
93
99
```julia
94
100
eachmatch(r"rgb\\(.*?\\)", s) |> collect
@@ -104,19 +110,20 @@ To display the image in a Jupyter or Pluto notebook, use the `HTML` function, or
104
110
105
111
## EPS images
106
112
107
-
EPS (Encapsulated PostScript) files created by Luxor (or any Cairo-based package) can be re-imported and placed on the current drawing with the [`placeeps`](@ref) function. The EPS commands are converted to the equivalent Luxor commands and evaluated immediately in the context of the current drawing and context.
113
+
EPS (Encapsulated PostScript) files created by Luxor (or any Cairo-based package) can be re-imported and placed on the current drawing with the [`placeeps`](@ref) function. This function converts the EPS commands to the equivalent Luxor commands and evaluates them immediately in the context of the current drawing.
108
114
109
115
!!! warning
110
116
111
117
This function is designed to extract just the coordinates of paths from an EPS
112
-
file. An EPS file can contain much more information about an image than just the
113
-
coordinates: there's image and pixel data, font data, linear color gradients,
114
-
and so on. These are not translated into Luxor functions. This function
115
-
interprets some of the EPS commands in a Cairo-generated EPS "Prolog"; EPS files created
116
-
by other applications will likely not contain this Cairo-generated Prolog, and
117
-
so won't be interpreted at all (or will go wrong in interesting ways).
118
+
file. An EPS file can contain much more information about an image than
119
+
coordinates: there migth be image and pixel data, font data, linear color
120
+
gradients, and so on. These are _not_ translated into equivalent Luxor
121
+
functions. This function interprets the EPS commands in a Cairo-generated EPS
122
+
"Prolog"; EPS files created by other applications will likely not contain this
123
+
Cairo-generated Prolog, and so won't be interpreted at all (or will go wrong in
124
+
interesting ways).
118
125
119
-
In the next example, an SVG file is placed and exported to an EPS file, then the EPS file is imported and placed on a new drawing with Luxor functions instead of EPS commands. It's placed at an angle for no good reason. When saved as SVG, the graphics will be in SVG format again. Some losses are to be expected!
126
+
In this example, an SVG file `linnux.svg`is placed and exported to an EPS file`linux.eps`, then this EPS file is imported and placed on a new SVG drawing using Luxor functions instead of EPS commands, respecting the current scale and orientation. Finally, when the SVG document is finished, the graphics will be in SVG format again.
0 commit comments