/** * Creates a new image scaler based on the given parameter String.<p> * * @param parameters the scale parameters to use */ public CmsImageScaler(String parameters) { init(); if (CmsStringUtil.isNotEmpty(parameters)) { parseParameters(parameters); } }
/** * Creates a new image scaler based on the given parameter String.<p> * * @param parameters the scale parameters to use */ public CmsImageScaler(String parameters) { init(); if (CmsStringUtil.isNotEmpty(parameters)) { parseParameters(parameters); } }
/** * Creates a new image scaler by reading the property <code>{@link CmsPropertyDefinition#PROPERTY_IMAGE_SIZE}</code> * from the given resource.<p> * * In case of any errors reading or parsing the property, * <code>{@link #isValid()}</code> will return <code>false</code>.<p> * * @param cms the OpenCms user context to use when reading the property * @param res the resource to read the property from */ public CmsImageScaler(CmsObject cms, CmsResource res) { init(); String sizeValue = null; if ((cms != null) && (res != null)) { try { CmsProperty sizeProp = cms.readPropertyObject(res, CmsPropertyDefinition.PROPERTY_IMAGE_SIZE, false); if (!sizeProp.isNullProperty()) { // parse property value using standard procedures sizeValue = sizeProp.getValue(); } } catch (Exception e) { LOG.debug(e.getMessage(), e); } } if (CmsStringUtil.isNotEmpty(sizeValue)) { parseParameters(sizeValue); } }
/** * Creates a new image scaler based on the given HTTP request.<p> * * The maximum scale size is checked in order to prevent DOS attacks. * Without this, it would be possible to request arbitrary huge images with a simple GET request, * which would result in Out-Of-Memory errors if the image is just requested large enough.<p> * * The maximum blur size is checked since this operation is know to also cause memory issues * with large images. If the original image is larger then this, no blur is applied before * scaling down, which will result in a less optimal but still usable scale result.<p> * * @param request the HTTP request to read the parameters from * @param maxScaleSize the maximum scale size (width or height) for the image * @param maxBlurSize the maximum size of the image (width * height) to apply blur */ public CmsImageScaler(HttpServletRequest request, int maxScaleSize, int maxBlurSize) { init(); m_maxBlurSize = maxBlurSize; String parameters = request.getParameter(CmsImageScaler.PARAM_SCALE); if (CmsStringUtil.isNotEmpty(parameters)) { parseParameters(parameters); if (isValid()) { // valid parameters, check if scale size is not too big if ((getWidth() > maxScaleSize) || (getHeight() > maxScaleSize)) { // scale size is too big, reset scaler init(); } } } }
/** * Creates a new image scaler based on the given HTTP request.<p> * * The maximum scale size is checked in order to prevent DOS attacks. * Without this, it would be possible to request arbitrary huge images with a simple GET request, * which would result in Out-Of-Memory errors if the image is just requested large enough.<p> * * The maximum blur size is checked since this operation is know to also cause memory issues * with large images. If the original image is larger then this, no blur is applied before * scaling down, which will result in a less optimal but still usable scale result.<p> * * @param request the HTTP request to read the parameters from * @param maxScaleSize the maximum scale size (width or height) for the image * @param maxBlurSize the maximum size of the image (width * height) to apply blur */ public CmsImageScaler(HttpServletRequest request, int maxScaleSize, int maxBlurSize) { init(); m_maxBlurSize = maxBlurSize; String parameters = request.getParameter(CmsImageScaler.PARAM_SCALE); if (CmsStringUtil.isNotEmpty(parameters)) { parseParameters(parameters); if (isValid()) { // valid parameters, check if scale size is not too big if ((getWidth() > maxScaleSize) || (getHeight() > maxScaleSize)) { // scale size is too big, reset scaler init(); } } } }
/** * Creates a new image scaler by reading the property <code>{@link CmsPropertyDefinition#PROPERTY_IMAGE_SIZE}</code> * from the given resource.<p> * * In case of any errors reading or parsing the property, * <code>{@link #isValid()}</code> will return <code>false</code>.<p> * * @param cms the OpenCms user context to use when reading the property * @param res the resource to read the property from */ public CmsImageScaler(CmsObject cms, CmsResource res) { init(); String sizeValue = null; if ((cms != null) && (res != null)) { try { CmsProperty sizeProp = cms.readPropertyObject(res, CmsPropertyDefinition.PROPERTY_IMAGE_SIZE, false); if (!sizeProp.isNullProperty()) { // parse property value using standard procedures sizeValue = sizeProp.getValue(); } } catch (Exception e) { // ignore } } if (CmsStringUtil.isNotEmpty(sizeValue)) { parseParameters(sizeValue); } }
scaler.parseParameters("w:50,h:18"); scaled = scaler.scaleImage(simapi.getBytes(source, Simapi.TYPE_PNG), targetName); writeFile(targetName, scaled);