Introduction to graphic design and image manipulation with open source tools
Offered by Guillaume Larocque, Quebec Centre for Biodiversity Science.
November 2023. Online.
GIMP
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.
To put the Toolbox icons in color, go to Edit>Preferences>Interface>Icon Theme> and choose Color.
Exercise 1 - Basic image cropping, rotation and resizing.
- Download this image from the National Library of Congress from 1915-1920.
- Open it in GIMP using File>Open.
- From the tools, click on the Rotate icon and rotate the image so to make the road at the back approximately horizontal.
- Use the “Crop tool” to keep only the part of the image that contains the main protagonists. Press ENTER to validate the selection
- 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.
- 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.
EXTRA:
- Convert the image to RGB by selecting Image>Mode>RGB.
- You can try to colorize the hats on the picture by selecting them with the Free select tool, choosing a foreground color on the left, and using the bucket tool to click on the selected region. You will have to adjust the the threshold of the bucket to fill the whole region and the opacity so that we can see through the color making it look more realistic.
- You can also give the image a sepia tone by choosing Color Balance, and moving the sliders towards the yellow and the red.
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.
- Download this image of a leaf and open it in GIMP.
- Go to unsplash and download the photo of an animal of your choice (or any photo with a subject of your choice). We will try to put that animal on the leaf. So choose something that works, but is original!
- 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.
- Click on Copy (CTRL-C) and then go to the GIMP page with the leaf and click on Edit>Paste as>New layer in place. In the list of layers, double-click on the layer name (Should be “clipboard”) and change it to the name of your animal.
- Using the Scale tool , resize the layer and re-position over the leaf with the Move tool.
- 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. You can also use the eraser tool for that.
- 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”.
- 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.
- 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.
- Go to unsplash or a site like wildtextures.com and download an image, texture or pattern to use as a background.
- 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.
- Adjust the colors of your background to your liking.
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.
- Download this image from a street scene in India.
- Significantly increase the contrast and saturation of the image.
- From the layer dialog, create a copy of the layer by clicking on the “Create a duplicate of the layer” icon.
- Click on the top layer and click on Colors>Desature to make the entire layer black and white.
- Click on the top layer and right-click “Add layer mask” and Black (Full transparency). Now the mask completely covers the layer below.
- 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.
- Repeat the operation so that you now only see the taxis in Yellow, and the rest of the image in black and white.
- For the second part of the exercise, hide the black and white layer with the mask and create two duplicates of the color layer.
- Click on the topmost layer and select Filters>Blur>Gaussian Blur. Choose a blur value of 15.
- 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.
- 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.
- 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.
- 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?
Exercise 4 - 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.
- 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>Animation>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!
Inkscape
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 5
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).
- 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%.
- 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.
- 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.
- 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.
- Go to Object>Fill and stroke>Stroke paint and click on the X to remove the stroke.
- Click on the square and then click on Path>Object to path. This will transform the object into a path that you can manipulate.
- 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.
- 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.
- Once you are satisfied with the shape of the star, click on it with the arrow and click on Edit>Duplicate.
- 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.
- 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.
- 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.
- Click on the green star and then on PAGE DOWN to move the star under the dark blue one.
- 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 6 - Using the svglite package and PDF.
If you are unable to do this exercize, you can download the SVG File here
- Install the svglite package and the spocc package
install.packages('svglite') install.packages('spocc')
- Load the library.
library(svglite)
- 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()
You can also save it as a PDF file and then edit it in Inkscape.
pdf("fig1.pdf") pie(country_count$Freq,labels=country_count$Var1) dev.off()
- You should now have a this file as an SVG or PDF on your computer. If you are unsure where it is, type getwd() to identify your working folder.
- You can now open this graphic and modify it in Inkscape.
- If you are curious, your can open the 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.
- 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.
Exercise 7 - Infographic!
- Open the graphic created in step 5 in Inkscape.
- Resize the document in File>Document properties to 240x160mm.
- 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.
- 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.
- You can change the size, the color and the position of the labels for the sections (country names).
- Click on the Create and edit text objects icon, and put a title for the infographic.
- 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.
- 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.
- 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.
- 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.
- 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.
- Export your infographic in PNG format.
- Here is an example of a completed infographic.
The R Magick package
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")