#' Function to add a logo onto an image
#'
#'@description This function adds a logo to the bottom right corner of the 
# image provided in 'file'.
#'@param file The path to the image 
#'@param logo The path to the logo image
#'@param logo_resize_percentage Scale factor for the logo, 1 being the original
#' size. The default value is 0.25.

add_logo <- function(file, logo, logo_resize_percentage = 0.25) {
  # file
  # logo: URL to the logo
  fig_width <- as.numeric(system(paste("identify -format '%w'", file), 
					intern = TRUE))
  logo_height <- as.numeric(system(paste("convert", logo, 
		"-resize", fig_width * 0.1, "-format '%h' info:", sep=" "),
					 intern = TRUE))
  system(paste0("convert ", file, 
		" -gravity south -background white -splice 0x",
		logo_height, " extended_fig.png"))
  system(paste0("convert extended_fig.png \\( ", 
		logo, " -resize ", fig_width * logo_resize_percentage,
		" \\) -gravity southeast -composite ",
		file))     
  file.remove("extended_fig.png")
}
