Search in sources :

Example 1 with ProductImageSize

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;
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) OutputContentFile(com.salesmanager.core.model.content.OutputContentFile) ProductImageSize(com.salesmanager.core.model.catalog.product.file.ProductImageSize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ServiceException (com.salesmanager.core.business.exception.ServiceException)1 ProductImageSize (com.salesmanager.core.model.catalog.product.file.ProductImageSize)1 OutputContentFile (com.salesmanager.core.model.content.OutputContentFile)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1