type = "additional";
id = imgName + "_View_" + viewNumber;
} else {
return ServiceUtil.returnError("View Type : " + type + " is wrong");
}
FlexibleStringExpander mainFilenameExpander = FlexibleStringExpander.getInstance(mainFilenameFormat);
String fileLocation = mainFilenameExpander.expandString(UtilMisc.toMap("location", "products", "type", type, "id", filenameToUse));
String filePathPrefix = "";
if (fileLocation.lastIndexOf("/") != -1) {
filePathPrefix = fileLocation.substring(0, fileLocation.lastIndexOf("/") + 1); // adding 1 to include the trailing slash
}
/* get original BUFFERED IMAGE */
resultBufImgMap.putAll(ImageTransform.getBufferedImage(imageServerPath + "/" + filePathPrefix + filenameToUse, locale));
if (resultBufImgMap.containsKey("responseMessage") && resultBufImgMap.get("responseMessage").equals("success")) {
bufImg = (BufferedImage) resultBufImgMap.get("bufferedImage");
// get Dimensions
imgHeight = (double) bufImg.getHeight();
imgWidth = (double) bufImg.getWidth();
if (imgHeight == 0.0 || imgWidth == 0.0) {
String errMsg = UtilProperties.getMessage(resource, "ScaleImage.one_current_image_dimension_is_null", locale) + " : imgHeight = " + imgHeight + " ; imgWidth = " + imgWidth;
Debug.logError(errMsg, module);
result.put("errorMessage", errMsg);
return result;
}
// new Filename Format
FlexibleStringExpander addFilenameExpander = mainFilenameExpander;
if (viewType.toLowerCase().contains("additional")) {
String addFilenameFormat = UtilProperties.getPropertyValue("catalog", "image.filename.additionalviewsize.format");
addFilenameExpander = FlexibleStringExpander.getInstance(addFilenameFormat);
}
/* scale Image for each Size Type */
Iterator<String> sizeIter = sizeTypeList.iterator();
while (sizeIter.hasNext()) {
String sizeType = sizeIter.next();
resultScaleImgMap.putAll(ImageTransform.scaleImage(bufImg, imgHeight, imgWidth, imgPropertyMap, sizeType, locale));
if (resultScaleImgMap.containsKey("responseMessage") && resultScaleImgMap.get("responseMessage").equals("success")) {
bufNewImg = (BufferedImage) resultScaleImgMap.get("bufferedImage");
// write the New Scaled Image
String newFileLocation = null;
if (viewType.toLowerCase().contains("main")) {
newFileLocation = mainFilenameExpander.expandString(UtilMisc.toMap("location", "products", "type", sizeType, "id", id));
} else if (viewType.toLowerCase().contains("additional")) {
newFileLocation = addFilenameExpander.expandString(UtilMisc.toMap("location", "products", "viewtype", viewType, "sizetype", sizeType,"id", id));
}
String newFilePathPrefix = "";
if (newFileLocation.lastIndexOf("/") != -1) {
newFilePathPrefix = newFileLocation.substring(0, newFileLocation.lastIndexOf("/") + 1); // adding 1 to include the trailing slash
}