Merge lp:~zorba-coders/zorba/bug867259 into lp:zorba

Proposed by Rodolfo Ochoa
Status: Merged
Approved by: Rodolfo Ochoa
Approved revision: 11382
Merged at revision: 11404
Proposed branch: lp:~zorba-coders/zorba/bug867259
Merge into: lp:zorba
Diff against target: 249 lines (+223/-0)
2 files modified
doc/zorba/indexpage.dox.in (+1/-0)
doc/zorba/tut_image.dox (+222/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/bug867259
Reviewer Review Type Date Requested Status
Rodolfo Ochoa Approve
William Candillon Approve
Review via email: mp+160515@code.launchpad.net

Commit message

Added tutorial to documentation

Description of the change

Added tutorial to documentation

To post a comment you must log in.
Revision history for this message
William Candillon (wcandillon) :
review: Approve
Revision history for this message
William Candillon (wcandillon) wrote :

Looks great!

Revision history for this message
Rodolfo Ochoa (rodolfo-ochoa) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug867259-2013-04-24T11-56-52.859Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'doc/zorba/indexpage.dox.in'
--- doc/zorba/indexpage.dox.in 2013-02-07 17:24:36 +0000
+++ doc/zorba/indexpage.dox.in 2013-04-23 22:24:25 +0000
@@ -62,4 +62,5 @@
6262
63\section tutorials Tutorials63\section tutorials Tutorials
64 - \ref web_crawler_tutorial64 - \ref web_crawler_tutorial
65 - \ref image_processing_tutorial
65*/66*/
6667
=== added file 'doc/zorba/tut_image.dox'
--- doc/zorba/tut_image.dox 1970-01-01 00:00:00 +0000
+++ doc/zorba/tut_image.dox 2013-04-23 22:24:25 +0000
@@ -0,0 +1,222 @@
1/**
2\page image_processing_tutorial Image Processing with Zorba
3
4\section image_proc Image Representation And Formats
5
6\subsection images Images
7
8Images are passed to the functions of the imaging library as xs:base64Binary types and
9any function returning an image will return it as xs:base64Binary type. For example,
10images read by the Zorba file module are already returned as xs:base64Binary and are
11ready to be used. Also, images written to disk using the file module will be ordinary
12binary data if one passes \c binary as serialization option.
13
14
15\subsection image_formats Image Formats
16
17Currently, the imaging library supports the following popular image formats: GIF, JPEG, TIFF, PNG and SVG.
18If any other format is needed, please contact us and we will see if it is possible to support the format.
19
20\subsection functions Functions
21
22All functions provided by the image library are functional and will either return the right value
23or raise an error. The library additionally offers interfaces with schema types in the function
24signatures (\c basicschema.xq, \c manipulationschema.xq, \c paintschema.xq, \c animationschema.xq) which can
25be used to directly validate certain types (e.g. color strings).
26
27
28\subsection colors Colors
29
30Colors are represented as strings in the same way they are used in html. A leading '#' character
31with 6 hexadecimal numbers following for red, green and blue values.
32
33Examples are:
34- Black: #000000
35- Red: #FF00000
36- Green: #00FF00
37- Blue: #0000FF
38
39\subsection modules Modules
40
41Zorba provides the following four modules for image processing:
42
43- <a href="/html/modules/zorba/image/basic">http://www.zorba-xquery.com/modules/image/basic</a> which is concerned with accessing basic image attributes, creating new images and converting their format.
44- <a href="/html/modules/zorba/image/manipulation">http://www.zorba-xquery.com/modules/image/manipulation</a> which is concerned with image manipulations like zooming, special effects etc.
45- <a href="/html/modules/zorba/image/paint">http://www.zorba-xquery.com/modules/image/paint</a> which is concerned with drawing different geometrical shapes and text to images.
46- <a href="/html/modules/zorba/image/manipulation">http://www.zorba-xquery.com/modules/image/animation</a> which is concerned with creating animated GIF images.
47
48This tutorial contains a small example for each of the modules.
49
50
51\section basic_imaging_functions Basic Imaging Functions
52
53\subsection creating_an_image Creating An Image
54
55In this example, we create a new image and return the width and type (image format) of the newly created image.
56
57\code
58import module namespace basic = "http://www.zorba-xquery.com/modules/image/basic";
59
60let $new-image as xs:base64Binary := basic:create(xs:unsignedInt(100), xs:unsignedInt(100), "GIF")
61let $width := basic:width($new-image)
62let $format := basic:type($new-image)
63return ($width, $format)
64\endcode
65
66
67\subsection explanation Explanation
68
69In line 3 \c $new-image is assigned the result of the basic:create command, so \c $new-image contains
70the xs:base64Binary representation of a plain white GIF image.
71
72In line 4 we use the basic:width command with new-image as argument to get the width of the image
73and in line 5 the basic:type function to get the format which are both passed back in line 6.
74
75\subsection expected_output Expected Output
76
77\code
78<?xml version="1.0" encoding="UTF-8"?>
79100 GIF
80\endcode
81
82\subsection accessing_efix_information Accessing Exif Information
83
84This example shows how to access the Exif information in JPEG images (also possible with TIFF images).
85
86\code
87import module namespace http = "http://expath.org/ns/http-client";
88import module namespace basic = "http://www.zorba-xquery.com/modules/image/basic";
89declare namespace h = "http://expath.org/ns/http-client";
90
91(: Get image from web :)
92let $req := <h:request method="GET"
93 href="http://www.zorba-xquery.com/tutorials/tutorialimages/exif.jpg"
94 auth-method="Basic"
95 send-authorization="true"
96 username="zorba"
97 password="blub"></h:request>
98let $res := http:read($req, ())[2]
99(: Using Image Library to extract exif tag :)
100return basic:exif($res, "DateTimeOriginal")
101\endcode
102
103\subsection explanation2 Explanation
104
105Lines 6 and 7 use the Zorba http library to get an image from the web.
106Then, in line 9 we pass the image to the \c basic:exif function requesting the value of the \c DateTimeOriginal tag, which we return.
107
108\subsection expected_output2 Expected Output
109\code
110<?xml version="1.0" encoding="UTF-8"?>
1112007-03-15T20:12:46+02:00
112\endcode
113
114\section manipulatin_images Manipulating Images
115
116In this example, we first download an image from the web using Zorba's http client and then
117apply a charcoal effect to that image returning the charcoaled image.
118
119\code
120import module namespace http = "http://expath.org/ns/http-client";
121import module namespace manipulation = "http://www.zorba-xquery.com/modules/image/manipulation";
122declare namespace h = "http://expath.org/ns/http-client";
123
124(: Get image from web :)
125let $req := <h:request method="GET" href="http://www.zorba-xquery.com/http-client/download.png" auth-method="Basic" send-authorization="true" username="zorba" password="blub" ></h:request>
126let $res := http:read($req, ())[2]
127(: Using Image Library to manipulate image :)
128let $manipulated-image := manipulation:charcoal($res, 2.0, 3.0)
129return $manipulated-image
130\endcode
131
132\subsection explanation3 Explanation
133
134Lines 6 and 7 use the Zorba http client to retrieve an image from the web.
135Then, in line 9, we assign \c $manipulated-image a manipulated version of the
136image by passing the fetched image to the \c manipulation:charcoal function
137that takes the image, performs the charcoal effect on it returns a charcoaled
138version of the image.
139
140\subsection expected_output3 Expected Output
141
142\image html tutorialimages/charcoaled.gif
143
144\section painting_images Painting Images
145
146In this example, we create a new blank image and then paint a circle and a rectangle on it before returning it.
147
148\code
149import module namespace basic = "http://www.zorba-xquery.com/modules/image/basic";
150import module namespace paint = "http://www.zorba-xquery.com/modules/image/paint";
151
152let $blank-image := basic:create(xs:unsignedInt(150), xs:unsignedInt(150), "PNG")
153let $image-circle := paint:draw-circle($blank-image, 75, 75, 50, "#00FF00", "#0000FF", 2, true())
154let $image-circle-and-rectangle := paint:draw-rectangle($image-circle, 25, 25, 75, 75, "#FF00FF", "#5F08AA", 1, true())
155return $image-circle-and-rectangle
156\endcode
157
158\subsection explanation4 Explanation
159
160In line 4 a blank image with PNG format is created (like in the first example of this tutorial).
161Then in line 5 we pass the blank image to the \c paint:draw-circle method which returns a version
162of the blank image with a circle on it.
163In line 6 we pass the image which already has a circle on it to the \c paint:draw-rectangle function
164which returns an additional rectangle painted on it.
165
166\subsection expected_output4 Expected Output
167
168\image html tutorialimages/painted.png
169
170\section creating_animated_gifs Creating Animated GIFS
171
172In this example, we create two blank images, paint a line on each, and use them to create an animated gif.
173
174\code
175import module namespace basic = "http://www.zorba-xquery.com/modules/image/basic";
176import module namespace paint = "http://www.zorba-xquery.com/modules/image/paint";
177import module namespace anim = "http://www.zorba-xquery.com/modules/image/animation";
178
179let $blank-image := basic:create(xs:unsignedInt(100), xs:unsignedInt(100), "GIF")
180let $first-image := paint:draw-line($blank-image, 50, 25, 50, 75, (), (), true())
181let $second-image := paint:draw-line($blank-image, 25, 50, 75, 50, (), (), true())
182return anim:create-animated-gif(($first-image, $second-image), xs:unsignedInt(15), xs:unsignedInt(0))
183\endcode
184
185\subsection explanation5 Explanation
186
187In lines 6 and 7, we create 2 images each containing a line painted on them.
188Then, in line 8, we return the output of anim:create-animated-gif (which is a GIF image)
189for which we pass the images from lines 6 and seven as arguments. The function composes
190them to an animated GIF image.
191
192\subsection expected_output5 Expected Output
193
194\image html tutorialimages/animated.gif
195
196\section putting_it_all_thogether Putting it all together: A More Extensive Example
197
198In this example, we will create an image displaying a scrolling text using different techniques from the examples above.
199
200\code
201import module namespace basic = "http://www.zorba-xquery.com/modules/image/basic";
202import module namespace paint = "http://www.zorba-xquery.com/modules/image/paint";
203import module namespace anim = "http://www.zorba-xquery.com/modules/image/animation";
204
205let $blank-image := basic:create(xs:unsignedInt(100), xs:unsignedInt(100), "GIF")
206let $i1 := paint:draw-text($blank-image, "Zorba Rocks", -10, 40, "Arial", (), "#FF0000")
207let $i2 := paint:draw-text($blank-image, "Zorba Rocks", 20, 40, "Arial", (), "#FF0000")
208let $i3 := paint:draw-text($blank-image, "Zorba Rocks", 40, 40, "Arial", (), "#FF0000")
209let $i4 := paint:draw-text($blank-image, "Zorba Rocks", 60, 40, "Arial", (), "#FF0000")
210let $i5 := paint:draw-text($blank-image, "Zorba Rocks", 80, 40, "Arial", (), "#FF0000")
211let $i6 := paint:draw-text($blank-image, "Zorba Rocks", 100, 40, "Arial", (), "#FF0000")
212let $i7 := paint:draw-text($blank-image, "Zorba Rocks", 20, 40, "Arial", (), "#FF0000")
213let $i8 := paint:draw-text($blank-image, "Zorba Rocks", 120, 40, "Arial", (), "#FF0000")
214return anim:create-morphed-gif(($i1, $i2, $i3, $i4, $i5, $i6, $i7, $i8), xs:unsignedInt(2), xs:unsignedInt(0), xs:unsignedInt(4))
215\endcode
216
217\subsection expected_output6 Expected Output
218
219\image html tutorialimages/extended.gif
220
221
222*/
0\ No newline at end of file223\ No newline at end of file
1224
=== added directory 'doc/zorba/tutorialimages'
=== added file 'doc/zorba/tutorialimages/animated.gif'
2Binary files doc/zorba/tutorialimages/animated.gif 1970-01-01 00:00:00 +0000 and doc/zorba/tutorialimages/animated.gif 2013-04-23 22:24:25 +0000 differ225Binary files doc/zorba/tutorialimages/animated.gif 1970-01-01 00:00:00 +0000 and doc/zorba/tutorialimages/animated.gif 2013-04-23 22:24:25 +0000 differ
=== added file 'doc/zorba/tutorialimages/charcoaled.gif'
3Binary files doc/zorba/tutorialimages/charcoaled.gif 1970-01-01 00:00:00 +0000 and doc/zorba/tutorialimages/charcoaled.gif 2013-04-23 22:24:25 +0000 differ226Binary files doc/zorba/tutorialimages/charcoaled.gif 1970-01-01 00:00:00 +0000 and doc/zorba/tutorialimages/charcoaled.gif 2013-04-23 22:24:25 +0000 differ
=== added file 'doc/zorba/tutorialimages/exif.jpg'
4Binary files doc/zorba/tutorialimages/exif.jpg 1970-01-01 00:00:00 +0000 and doc/zorba/tutorialimages/exif.jpg 2013-04-23 22:24:25 +0000 differ227Binary files doc/zorba/tutorialimages/exif.jpg 1970-01-01 00:00:00 +0000 and doc/zorba/tutorialimages/exif.jpg 2013-04-23 22:24:25 +0000 differ
=== added file 'doc/zorba/tutorialimages/extended.gif'
5Binary files doc/zorba/tutorialimages/extended.gif 1970-01-01 00:00:00 +0000 and doc/zorba/tutorialimages/extended.gif 2013-04-23 22:24:25 +0000 differ228Binary files doc/zorba/tutorialimages/extended.gif 1970-01-01 00:00:00 +0000 and doc/zorba/tutorialimages/extended.gif 2013-04-23 22:24:25 +0000 differ
=== added file 'doc/zorba/tutorialimages/painted.png'
6Binary files doc/zorba/tutorialimages/painted.png 1970-01-01 00:00:00 +0000 and doc/zorba/tutorialimages/painted.png 2013-04-23 22:24:25 +0000 differ229Binary files doc/zorba/tutorialimages/painted.png 1970-01-01 00:00:00 +0000 and doc/zorba/tutorialimages/painted.png 2013-04-23 22:24:25 +0000 differ

Subscribers

People subscribed via source and target branches