You could use the R "raster", "rasterVis" and "ggplot2" packages to automate this quite nicely. You have considerable control of very simple (just the raster) or customized plots using the R low-level plotting engine or higher level plotting like ggplot2. You can also easily call other plotting devices to output other formats including: tiff, bmp, png or pdf. I have used this exact approach in concert with the animation package to create raster, html and giff, animations.
Here is an example using a raster from the raster package. Note; I commented out the jepg device call and the dev.off() so the result will plot to a window device.
require(raster)
require(rasterVis)
require(ggplot2)
# Add example raster
r <- raster(system.file("external/test.grd", package="raster"))
names(r) <- c('meuse')
# Call ggplot through gplot interface and then call jpeg graphic device
#jpeg(paste(dir, "RasterPlot.jpg", sep="/"), width=480, height=480, quality=100)
theme_set(theme_bw())
rplot <- ( gplot(r) + geom_tile(aes(fill = value)) +
facet_wrap(~ variable) +
scale_fill_gradient(low='green', high='red') +
coord_equal() )
rplot
#dev.off()
You can use R's looping structure to automate the process.
require(raster)
require(rasterVis)
require(ggplot2)
# Set raster and output directories
ImageDir = "C:/Images"
OutDir = "C:/Images/jpegs"
# Make a raster stack of all img files in ImageDir
rstack <- stack( list.files(ImageDir, pattern="img$", full.names=TRUE) )
# For loop to create jpeg for each raster. Name is same as raster
for(i in 1:nlayers(rstack)) {
jpeg(paste(OutDir, paste( names(rstack)[i], "jpg", sep="."), sep="/"),
width=480, height=480, quality=100)
theme_set(theme_bw())
rplot <- ( gplot(rstack[[i]]) + geom_tile(aes(fill=value)) +
facet_wrap(~ variable) +
scale_fill_gradient(low='green', high='red') +
coord_equal() )
print( rplot )
dev.off()
}