public Dimension getSizeForImageManipulation(ImageMetadata imageMetadata, RequestData requestData) {

        Dimension d = new Dimension();

        Dimension regionSize = getRegionCoordinates(requestData, imageMetadata).getSize();
        
        log.debug("getSizeForImageManipulation - passed");
        

        if (requestData.isSizeFull()) {
            return regionSize;
        }

        String sizeToSplit = requestData.getSize();

        if (requestData.isSizeBestFit()) {
            sizeToSplit = sizeToSplit.substring(1);
        }

        String[] coords = sizeToSplit.split(RequestData.REQUEST_DELIMITER);

        if (requestData.isSizeHeightDeterminedByWidth()) {
            d.width = Integer.parseInt(coords[0]);
            /* replaced 
             * d.height = (d.width * regionSize.height) / regionSize.width;
             * with
             */
           d.height = new BigDecimal((d.width * regionSize.height))
           		.divide(new BigDecimal(regionSize.width),2, RoundingMode.HALF_UP)
                .setScale(0, RoundingMode.HALF_EVEN).intValue();
           log.debug("isSizeHeightDeterminedByWidth d.height [" + d.height + "]");
           /* end replace */
           
            return d;
        }

        if (requestData.isSizeWidthDeterminedByHeight()) {
            d.height = Integer.parseInt(coords[1]);
            /* replaced
             * d.width = (d.height * regionSize.width) / regionSize.height;
             * with
             */
           log.debug("d.height [" + d.height + "]");
           log.debug("regionSize.width [" + regionSize.width + "]");
           log.debug("regionSize.height [" + regionSize.height + "]");
            d.width = new BigDecimal((d.height * regionSize.width))
           		.divide(new BigDecimal(regionSize.height),2, RoundingMode.HALF_UP)
           		.setScale(0, RoundingMode.HALF_EVEN).intValue(); 
           log.debug("isSizeWidthDeterminedByHeight d.width [" + d.width + "]");
           /* end replace */
            
            return d;
        }

        if (requestData.isSizePercentage()) {
            BigDecimal sizePercent = requestData.getSizePercentageAsDecimal();
            d.width = sizePercent.multiply(new BigDecimal(regionSize.width).setScale(0, RoundingMode.HALF_EVEN))
                                 .intValue();
            d.height = sizePercent.multiply(new BigDecimal(regionSize.height).setScale(0, RoundingMode.HALF_EVEN))
                                  .intValue();
            return d;
        }

        if (requestData.isSizeBestFit()) {
            if (!requestData.isRegionFull()) {
                regionSize = requestParser.getRegionValues(requestData, imageMetadata)
                                          .getSize();
            }
            BigDecimal scaleX = new BigDecimal(String.valueOf((double) Integer.parseInt(coords[0]) / regionSize.width));
            BigDecimal scaleY = new BigDecimal(String.valueOf((double) Integer.parseInt(coords[1]) / regionSize.height));

            if (scaleX.compareTo(scaleY) < 0) {
                d.width = (new BigDecimal(regionSize.width)).multiply(scaleX)
                                                            .setScale(0, RoundingMode.HALF_EVEN)
                                                            .intValue();
                d.height = (new BigDecimal(regionSize.height)).multiply(scaleX)
                                                              .setScale(0, RoundingMode.HALF_EVEN)
                                                              .intValue();
            } else {
                d.width = (new BigDecimal(regionSize.width)).multiply(scaleY)
                                                            .setScale(0, RoundingMode.HALF_EVEN)
                                                            .intValue();
                d.height = (new BigDecimal(regionSize.height)).multiply(scaleY)
                                                              .setScale(0, RoundingMode.HALF_EVEN)
                                                              .intValue();

            }
            return d;
        }

        d.width = Integer.parseInt(coords[0]);
        d.height = Integer.parseInt(coords[1]);

        return d;
    }