# Introduction to graphic design and image manipulation with open source tools

Offered by Guillaume Larocque, Quebec Centre for Biodiversity Science.

October 23, 2019. McGill University.

To install GIMP, go to this site and follow instructions.

To put GIMP in single window mode, click on Window>Single Window Mode, and restart GIMP.

### Exercise 1 - Basic image cropping, rotation and resizing.

1. Download this image from the National Library of Congress from 1915-1920.
2. Open it in GIMP using File>Open.
3. From the tools, click on the Rotate icon and rotate the image so to make the road at the back approximately horizontal.
4. Use the “Rectangle Select” tool to keep only the part of the image that contains the main protagonists.
5. Click on Image>“Crop to selection” to remove the non-selected portion of the image.
6. Use the Colors>Curve interface to make the dark areas of the image a bit darker, while making the other shades of the image untouched. Your curve should look like this:
7. Use the Clone tool and the Healing tool to remove small specks in the image. After clicking on the tool's icon, click on a reference area close to the speck you want to remove, and then click CTRL and click on the speck. Make sure that the brush size is appropriate. You can play with the opacity of a brush for a more subtle effect.
8. Use Image>“Scale image” and the “Crop” tool with a fixed size to obtain an image that is exactly 120dpi (pixels per inch) at 8.5×11 inches. Use the Image>Print size to verify that it works.

### Exercise 2 - Layers, cropping and manipulation of colors.

You are given the image of a leaf, and you have to add an animal of your choice from another photo on top of the leaf.

1. Download this image of a leaf and open it in GIMP.
2. Go to unsplash and download the photo of an animal of your choice. We will try to put that animal on the leaf. So choose something that works, but is original!
3. Open the image you downloaded in GIMP. Use the Free select tool to delineate carefully the outline of the animal you wish to extract. At this point, you can just delineate the outside.
4. Click on Copy (CTRL-C) and then go to the GIMP page with the leaf and click on Edit>Paste as>New layer. In the list of layers, double-click on the layer name (Should be “clipboard”) and change it to the name of your animal.
5. Using the Scale tool , resize the layer and re-position over the leaf with the Move tool.
6. If there are parts of the animal that you would like to crop out (e.g. space between the legs), delineate it with the Free select tool and press DELETE to remove it.
7. Click on the layer in the layer menu and then open Colors>“Brightness, Contrast” to adjust the image so that it looks realistic on the leaf. Do the same with Colors>“Hue, saturation”.
8. Right-click on the layer that contains the leaf in the layer menu and choose Add Alpha Channel. This will allow the layer to contain transparent parts.
9. Click on the Fuzzy Select Tool . Click on the background of the photo with the leaf. Adjust the threshold value in the Tool options and click again on the background until you include all of the background, but exclude the leaf. Click on DELETE to remove the background.
10. Go to unsplash or a site like wildtextures.com and download an image, texture or pattern to use as a background.
11. Download and open the texture in GIMP. Copy the image and click on Edit>Paste as>New layer. Click on the layer in the layer menu and drag it below the other layers.

### Exercise 3 - Layer masks.

In this exercise, you will play with layer masks in GIMP. You will first select an element of an image and make the rest of the image black and white. You will then apply an effect know as “tilt-shift” photography to your photo. This effect artificially plays with the depth-of-field of the image to make it look like only the central elements are in focus. This gives an overall impression that the whole image is very small, like a scale model.

2. Significantly increase the contrast and saturation of the image.
3. From the layer dialog, create a copy of the layer by clicking on the “Create a duplicate of the layer” icon.
4. Click on the top layer and click on Colors>Desature to make the entire layer black and white.
5. Click on the top layer and right-click “Add layer mask” and Black (Full transparency). Now the mask completely covers the layer below.
6. Click on the Paintbrush tool, and select a size of +/- 50. With the paintbrush, click and move the cursor on the yellow taxis on the image. You can always click on the eye icon on the layer dialog to temporarily hide the black and white layer to reveal the color layer below.
7. Repeat the operation so that you now only see the taxis in Yellow, and the rest of the image in black and white.
1. For the second part of the exercise, hide the black and white layer with the mask and create two duplicates of the color layer.
2. Click on the topmost layer and select Filters>Blur>Gaussian Blur. Choose a blur value of 15.
3. Right click on the topmost layer and select Add Mask> White (Full opacity). This will make the non-blury layer visible everywhere where it is opaque on the Mask.
4. Click on the gradient tool and create a gradient that starts from the middle (vertically) of the image and goes down to one-third of the image. This should make the bottom part of the image blurry.
5. Repeat the operation with the other duplicate of the image for the top part. Start by applying the Gaussian blur and then add the mask and apply the gradient from the center to the top third of the image.
6. Your image should now be blurry on the top and bottom and should have the tilt-shift look. What happens if you now make the mask from step 1 visible? What if you change their order?

To install Inkscape, go to this site and download the version for your platform. If you are on Mac OSX, carefully read the extra steps needed.

### Exercise 4

You receive a logo in Bitmap format that you have to recreate because the image resolution is too low. Your task is to recreate this logo in Inkscape. It is the logo of a group of students working on Northern Research in Quebec (see https://qcbs.ca/iiw).

1. In Inkscape, click on File>Document Properties. Specify a width and height of 200 mm. Note that the background is transparent by default. To have a white background for the output image, click on Background color, and make the Alpha channel opacity (A) 100%.
2. Click on File>Import and choose the iiw_logo.png file from your computer. This will be used as a reference. You can make it bigger and place it beside the canvas.
3. Start by creating a square that fills most of the canvas. When done, click on the square and adjust the width W and height H on the top menu so that both values are equal.
4. Click on the square, then on the droplet icon , and click on the darker blue part of the bitmap icon to make the square the same color as one of the “stars” from the icon.
5. Go to Object>Fill and stroke>Stroke paint and click on the X to remove the stroke.
6. Click on the square and then click on Path>Object to path. This will transform the object into a path that you can manipulate.
7. Making sure that the “Edit paths by nodes” () is selected, double click on the middle of one of the sides of the square to add a node. Do this for each side.
8. Drag the corner nodes of the square to move them toward the center to reproduce the general shape of the star. Make sure all sides are identical and the image is symmetrical.
9. Click and drag on one of the center nodes while holding the SHIFT key to pull out a handle that allows to adjust the curvature of the lines. Click on the same node while holding the SHIFT key to add curvature in the other direction. Give all sides the proper curvature using this approach.
10. Once you are satisfied with the shape of the star, click on it with the arrow and click on Edit>Duplicate.
11. Click on the new star that was just created on top of the other one, click on the droplet icon and then click on the paler turquoise color of the bitmap icon to make it the same color.
12. Click twice on the turquoise star until you see the rotating handles. Click on one of the corner handles and rotate the star 45 degrees.
13. Center both stars on the page by clicking on each one, clicking on Object>Align and distribute and by selecting Relative to page, and the Center on vertical axis icon.
14. Click on the green star and then on PAGE DOWN to move the star under the dark blue one.
15. Your logo should look something like this:
16. Export your logo as a PNG image by clicking on File>Export PNG image. Click on Export area “Page” and then select a size of 500x500px.

### Exercize 5 - Using the svglite package.

If you are unable to do this exercize, you can download the SVG File here

1. Install the svglite package and the spocc package
install.packages('svglite')
install.packages('spocc')
library(svglite)
3. Execute the following code to create a pie chart, or adapt the code for another species or to use your own data.
df <- occ(query = 'Puma concolor', from = 'gbif',limit=10000)
country_count=as.data.frame(table(df$gbif$data$Puma_concolor$country),stringsAsFactors=FALSE)
country_count<-country_count[order(country_count$Freq),] country_count<-rbind(country_count[country_count$Freq>50,],data.frame(Var1='Other countries',Freq=sum(country_count[country_count$Freq<=50,'Freq']))) svglite("fig1.svg") pie(country_count$Freq,labels=country_count$Var1) dev.off() 4. You should now have a this file as an SVG on your computer. If you are unsure where it is, type getwd() to identify your working folder. 5. You can now open this graphic and modify it in Inkscape. 6. If you are curious, your can open this SVG file in Notepad or TextEdit to check the structure of the SVG/XML file. You could modify the file in text form if you wanted. 7. Note that the text created with svglite has a fixed width (textLength is specified in the xml text tag. So, if you increase the size of the font, it will become higher but not wider. To fix this problem, open the XML Editor (Edit>XML Editor) and clear the textLength section for text objects. You could also make this change by editing the SVG in a text editor. 8. Note that you could also save your file in pdf format and open it in Inkscape as a PDF. It will still be a vector file, but it may be easier to use in some cases than the SVG format. pdf("fig1.pdf") pie(country_count$Freq,labels=country_count$Var1) dev.off() ### Exercise 6 - Infographic! 1. Open the graphic created in step 5 in Inkscape. 2. Resize the document in File>Document properties to 240x160mm. 3. Choose a color gradient. To facilitate this task, you can select from the color palette at the bottom of the screen. Next, click on the sectors of the diagram to change the colors and make a gradient from dark for the larger sectors to lighter colors for the smaller sectors. 4. Choose a contrasting dark color for the background of the infographic. Next, create a rectangle that is slightly larger than the page, and specify a background color (Fill) for it. You can use a slight color gradient for the background. To do so, in the Fill and Stroke section, you click on the Gradients option, click on the square hook at the bottom of the rectangle, specify a color for that, then click on the circular hook and choose another color for that. 5. You can change the size, the color and the position of the labels for the sections (country names). 6. Click on the Create and edit text objects icon, and put a title for the infographic. 7. To add a small paragraph of text, click/drag to delineate where the section of text will be. This way, lines of text will wrap within that section. 8. Choose a photo that you want to put at the centre of the diagram on EOL (http://eol.org) by searching with the name of the species. Save this photo to your computer and import in Inkscape with File>Import. 9. Resize approximately the image and click on the Create circles, ellipses and arcs icon. Click-drag on the photo to delineate the part of the photo that you want to put in the circle. You can put the circle semi-transparent (Fill, change Opacity) to make this easier. Then, select the photo and the circle by clicking and holding the SHIFT key. Click on Object>Clip>Set. This should crop the photo to a circle. You can release the clip at any time to undo this operation and get the complete photo back. 10. Download a silhouette of your animal, or this Cougar silhouette and open it in Inkscape as a separate file. Click on the silhouette and Path>Trace bitmap. Choose Colors, specify 2 passes, and click on OK. You can then select the silhouette in vector format by clicking on it and copy-paste it on your infographic. Now, position it and choose a color. 11. You can experiment by adding drop shadows to certain elements. To do so, select and element and click on Filters>Shadows and Glows>Drop shadow. 12. Export your infographic in PNG format. 13. Here is an example of a completed infographic. ### Exercise 7 - GIFs! You will be making a GIF animation that highlights how cool your research is! • Find some photos or graphs from your research that you want to highlight, or use the infographic you created above. • In GIMP, click on File>New and select a 640×480 document with a White background. • Open the content you want to put in the animation in GIMP and copy it as new layers using Edit>Paste as…>New layer. Resize the content to fit into the page using the Scale Tool. • Reorder the layers, knowing that the bottom layer will be played first and the top layer last. • Change the name of each layer to designate the associated content. After the name of the layer add (500ms) to get something like: “First photo(500ms)”. The number in parenthesis is the duration of this slide in the GIF animation. • For slides with text, click on the Text tool and choose the font and font size from the Tool options before adding the text. When you are done placing and resizing the text, add (500ms) to the name of the text layer. • To give a background to your text, first choose a foreground color by clicking on the Foreground and Background Color icon. Then, add an empty layer to the bottom of the text (by clicking the Create a new layer icon ) that has that foreground color. When satisfied with both the text and the background, right click on the text layer and choose Merge Down. The text is now fused with the background and you can't remove it. • You can test your animation by clicking on Filters>Animate>Playback. • When you are happy with your work, choose File>Export as>GIF Image, and then click on As animation, leaving the other options unmodified. If it asks if you want to crop, click yes. • You can now open your animation in a web browser! Complete documentation is here. Let's add text and a border to an image. library(magick) iiw <- image_read("https://qcbs.ca/wp-content/uploads/2017/10/banner_iiw2.jpg") iiw iiw<-image_annotate(iiw, "Intercultural indigenous workshop", size = 30, gravity = "north", color = "white",font="verdana") iiw<-image_border(iiw, "#cccccc", "20x20") iiw image_write(iiw, "iiw.jpg") Make an animation and save it as a GIF. This uses the gganimate functionality of ggplot2. library(magick) library(gapminder) library(ggplot2) img <- image_graph(600, 400, res = 96) datalist <- split(gapminder, gapminder$year)
out <- lapply(datalist, function(data){
p <- ggplot(data, aes(gdpPercap, lifeExp, size = pop, color = continent)) +
scale_size("population", limits = range(gapminder$pop)) + geom_point() + ylim(20, 90) + scale_x_log10(limits = range(gapminder$gdpPercap)) + ggtitle(data\$year) + theme_classic()
print(p)
})
dev.off()
img <- image_background(image_trim(img), 'white')
animation <- image_animate(img, fps = 2)
print(animation)
image_write(animation, "animation.gif")