use of com.salesmanager.core.model.catalog.product.file.ProductImageSize in project shopizer by shopizer-ecommerce.
the class ImagesController method printImage.
/**
* Exclusive method for dealing with product images
* @param storeCode
* @param productCode
* @param imageName
* @param extension
* @param request
* @return
* @throws IOException
*/
@RequestMapping(value = "/static/products/{storeCode}/{productCode}/{imageSize}/{imageName}.{extension}", produces = { "image/gif", "image/jpg", "image/png", "application/octet-stream" })
@ResponseBody
public byte[] printImage(@PathVariable final String storeCode, @PathVariable final String productCode, @PathVariable final String imageSize, @PathVariable final String imageName, @PathVariable final String extension, HttpServletRequest request) throws IOException {
// product image small
// example small product image -> /static/products/DEFAULT/TB12345/SMALL/product1.jpg
// example large product image -> /static/products/DEFAULT/TB12345/LARGE/product1.jpg
/**
* List of possible imageType
*/
ProductImageSize size = ProductImageSize.SMALL;
if (FileContentType.PRODUCTLG.name().equals(imageSize)) {
size = ProductImageSize.LARGE;
}
OutputContentFile image = null;
try {
image = productImageService.getProductImage(storeCode, productCode, new StringBuilder().append(imageName).append(".").append(extension).toString(), size);
} catch (ServiceException e) {
LOGGER.error("Cannot retrieve image " + imageName, e);
}
if (image != null) {
return image.getFile().toByteArray();
} else {
// empty image placeholder
return tempImage;
}
}
Aggregations