use of ai.elimu.model.enums.content.ImageFormat in project webapp by elimu-ai.
the class ImageListController method handleRequest.
@RequestMapping(method = RequestMethod.GET)
public String handleRequest(Model model, HttpSession session) {
logger.info("handleRequest");
Contributor contributor = (Contributor) session.getAttribute("contributor");
// To ease development/testing, auto-generate Images
List<Image> imagesGenerated = generateImages(contributor.getLocale());
for (Image image : imagesGenerated) {
Image existingImage = imageDao.read(image.getTitle(), image.getLocale());
if (existingImage == null) {
ImageFormat imageFormat = ImageFormat.PNG;
image.setContentType("image/png");
String fileName = image.getTitle() + "." + imageFormat.toString().toLowerCase();
logger.info("Looking up file \"" + image.getTitle() + "." + imageFormat.toString().toLowerCase() + "\"...");
URL url = getClass().getResource(fileName);
logger.info("url.getPath(): " + url.getPath());
try {
byte[] imageBytes = IOUtils.toByteArray(url);
image.setBytes(imageBytes);
image.setImageFormat(imageFormat);
int[] dominantColor = ImageColorHelper.getDominantColor(image.getBytes());
image.setDominantColor("rgb(" + dominantColor[0] + "," + dominantColor[1] + "," + dominantColor[2] + ")");
imageDao.create(image);
} catch (IOException ex) {
logger.error(null, ex);
}
}
}
List<Image> images = imageDao.readAllOrdered(contributor.getLocale());
model.addAttribute("images", images);
return "content/multimedia/image/list";
}
Aggregations