use tryCatch to fallback to JPEG if PNG doesn't work