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")
}


#fig <- "/home/bsc/bsc032339/recipe_tas_20241106160039/plots/Meto-France-System8/ERA5/evmos/tas/forecast_most_likely_tercile-20240801_ft01.png"

#fig <- "/home/bsc/bsc032339/recipe_tas_20241106160039/plots/Meto-France-System8/ERA5/evmos/tas/forecast_ensemble_median-20240801_ft01.png"

#fig <- "/home/bsc/bsc032339/recipe_tas_20241106160039/plots/Meto-France-System8/ERA5/evmos/tas/rpss-august_ft01.png"

#fig_width <- as.numeric(system(paste("identify -format '%w'", fg), intern = TRUE))

#logo <- "rsz_rsz_bsc_logo.png"
#logo_height <- as.numeric(system(paste("convert", logo, "-resiz", fig_width * 0.1, "-format '%h' info:", sep=" "), intern = TRUE))

#system(paste0("convert ", fig, " -gravity south -background whie -splice 0x", logo_height, " extended_fig.png"))

#system(paste0("convert extended_fig.png \\( ", logo, " -resize , map_width * 0.25, " \\) -gravity southeast -composite extended_fig.png"))
