int height = target.getHeight(); int width = target.getWidth(); if ((width > 0) && (getWidth() > 0)) { float scale = (float)width / (float)getWidth(); height = Math.round(getHeight() * scale); } else if ((height > 0) && (getHeight() > 0)) { float scale = (float)height / (float)getHeight(); width = Math.round(getWidth() * scale); } else if (isValid() && !target.isValid()) { width = getWidth(); height = getHeight(); if ((target.getType() == 1) && (!target.isValid())) { if ((target.getWidth() > 0) && (getWidth() < width)) { height = getHeight(); } else if ((target.getHeight() > 0) && (getHeight() < height)) { width = getWidth(); return new CmsImageScaler(target, width, height);
CmsImageScaler cropScaler = null; cropScaler = new CmsImageScaler(scaleParam); if (scaler.getType() == 5) { cropScaler.setWidth(cropScaler.getCropWidth()); cropScaler.setHeight(cropScaler.getCropHeight()); scaler = cropScaler.getCropScaler(scaler); if (((scaler.getHeight() <= 0) || (scaler.getWidth() <= 0)) || ((scaler.getType() == 5) && scaler.isValid() && !scaler.isCropping())) { if (original.isValid()) { scaler = original.getReScaler(scaler);
/** * Returns the initialized image scaler object used to generate thumbnails for the dialog form.<p> * * @return the initialized image scaler object used to generate thumbnails for the dialog form */ protected CmsImageScaler getImageScaler() { if (m_imageScaler == null) { // not initialized, create image scaler with default settings m_imageScaler = new CmsImageScaler(); m_imageScaler.setWidth(THUMB_WIDTH); m_imageScaler.setHeight(THUMB_HEIGHT); m_imageScaler.setRenderMode(Simapi.RENDER_SPEED); m_imageScaler.setColor(new Color(0, 0, 0)); m_imageScaler.setType(1); } return m_imageScaler; }
/** * Creates a new image scaler based on the given base scaler and the given width and height.<p> * * @param base the base scaler to initialize the values with * @param width the width to set for this scaler * @param height the height to set for this scaler */ protected CmsImageScaler(CmsImageScaler base, int width, int height) { initValuesFrom(base); setWidth(width); setHeight(height); }
/** * @see java.lang.Object#clone() */ @Override public Object clone() { CmsImageScaler clone = new CmsImageScaler(); clone.initValuesFrom(this); return clone; }
CmsImageScaler scaler = new CmsImageScaler(getContent(), getRootPath()); if (!scaler.isValid()) { if (scaler.isDownScaleRequired(m_imageDownScaler)) { CmsImageScaler downScaler = scaler.getDownScaler(m_imageDownScaler); m_content = downScaler.scaleImage(m_content, m_rootPath); scaler.setHeight(downScaler.getHeight()); scaler.setWidth(downScaler.getWidth()); CmsProperty p = new CmsProperty(CmsPropertyDefinition.PROPERTY_IMAGE_SIZE, null, scaler.toString());
m_defaultScaleParams = new CmsImageScaler(m_galleryTypeParams); if (!m_defaultScaleParams.isValid()) { m_defaultScaleParams.setType(0); m_defaultScaleParams.setPosition(0); m_defaultScaleParams.setWidth(120); m_defaultScaleParams.setHeight(90); m_defaultScaleParams.setColor(new Color(221, 221, 221));
int height = target.getHeight(); int width = target.getWidth(); int type = target.getType(); if (target.isValid()) { float maxWidth = target.getMaxWidth() > 0 ? target.getMaxWidth() : height; float maxHeight = target.getMaxHeight() > 0 ? target.getMaxHeight() : width; float scaleOfImage = (float)getWidth() / (float)getHeight(); float[] scales = new float[3]; scales[0] = (float)width / (float)height; scales[1] = width / maxHeight; scales[2] = maxWidth / height; int useScale = calculateClosest(scaleOfImage, scales); int[] dimensions; switch (useScale) { case 1: dimensions = calculateDimension(getWidth(), getHeight(), width, (int)maxHeight); break; case 2: dimensions = calculateDimension(getWidth(), getHeight(), (int)maxWidth, height); break; case 0: default: dimensions = calculateDimension(getWidth(), getHeight(), width, height); break; if ((width > 0) && (getWidth() > 0)) {
/** * Returns a new image scaler that is a width based down scale from the size of <code>this</code> scaler * to the given scaler size.<p> * * If no down scale from this to the given scaler is required because the width of <code>this</code> * scaler is not larger than the target width, then the image dimensions of <code>this</code> scaler * are unchanged in the result scaler. No up scaling is done!<p> * * @param downScaler the image scaler that holds the down scaled target image dimensions * * @return a new image scaler that is a down scale from the size of <code>this</code> scaler * to the given target scaler size */ public CmsImageScaler getWidthScaler(CmsImageScaler downScaler) { int width = downScaler.getWidth(); int height; if (getWidth() > width) { // width is too large, re-calculate height float scale = (float)width / (float)getWidth(); height = Math.round(getHeight() * scale); } else { // width is ok width = getWidth(); height = getHeight(); } // now create and initialize the result scaler return new CmsImageScaler(downScaler, width, height); }
CmsImageScaler originalScaler) { int targetWidth = m_scaler.getWidth(); int targetHeight = m_scaler.getHeight(); int originalWidth = originalScaler.getWidth(); int originalHeight = originalScaler.getHeight(); CmsImageScaler hiDpiScaler = (CmsImageScaler)scaler.clone(); hiDpiScaler.setWidth(width); hiDpiScaler.setHeight(height); if (hiDpiScaler.isValid()) { imageSrc += hiDpiScaler.toRequestParam();
if (scaleStr != null) { reScaler = new CmsImageScaler(scaleStr[0]); scaler = reScaler.getCropScaler(scaler); if ((scaler.getHeight() <= 0) || (scaler.getWidth() <= 0)) { CmsImageScaler original = new CmsImageScaler(cms, imageRes); if (original.isValid()) { scaler = original.getReScaler(scaler); if (scaler.isValid()) { imageLink += scaler.toRequestParam(); if (scaler.isValid()) { result.append(scaler.getWidth()); result.append("\""); result.append(" height=\""); result.append(scaler.getHeight()); result.append("\"");
initCropArea(); LOG.debug(Messages.get().getBundle().key(Messages.ERR_UNABLE_TO_SCALE_IMAGE_2, rootPath, toString())); if (isCropping()) { if ((getType() == 0) && ((m_cropHeight > image.getHeight()) || (m_cropWidth > image.getWidth()))) { Color color = getColor(); if (isCropping()) { if ((getType() == 6) || (getType() == 7)) { image = scaler.cropPointToSize(image, m_cropX, m_cropY, getType() == 6, m_cropWidth, m_cropHeight); } else { m_cropWidth, m_cropHeight, getWidth(), getHeight(), color); switch (getType()) { image = scaler.resize(image, getWidth(), getHeight(), color, getPosition(), false); imageProcessed = true; break; case 2:
} else if (SCALE_PARAM_TYPE.equals(k)) { setType(CmsStringUtil.getIntValue(v, -1, CmsImageScaler.SCALE_PARAM_TYPE)); } else if (SCALE_PARAM_COLOR.equals(k)) { setColor(v); } else if (SCALE_PARAM_POS.equals(k)) { setPosition(CmsStringUtil.getIntValue(v, -1, CmsImageScaler.SCALE_PARAM_POS)); } else if (SCALE_PARAM_QUALITY.equals(k)) { setQuality(CmsStringUtil.getIntValue(v, 0, k)); } else if (SCALE_PARAM_RENDERMODE.equals(k)) { setRenderMode(CmsStringUtil.getIntValue(v, 0, k)); } else if (SCALE_PARAM_FILTER.equals(k)) { setFilters(v); } else { if (LOG.isDebugEnabled()) { initCropArea();
StringBuffer link = new StringBuffer(256); link.append(getCms().getSitePath(res)); link.append(getImageScaler().toRequestParam()); result.append(getJsp().link(link.toString())); result.append("\" border=\"0\" alt=\"\" width=\""); result.append(getImageScaler().getWidth()); result.append("\" height=\""); result.append(getImageScaler().getHeight()); result.append("\">");
CmsImageScaler origImage = new CmsImageScaler(getCms(), res); CmsImageScaler scaler = new CmsImageScaler(); scaler.setWidth(60); scaler.setHeight(60); CmsImageScaler resultScaler = origImage.getDownScaler(scaler); if (resultScaler == null) { resultScaler = origImage;
CmsImageScaler scaler = new CmsImageScaler(tempFile.getContents(), tempFile.getRootPath()); if (scaler.isValid()) { scaler.setType(2); scaler.setHeight(192); scaler.setWidth(192); byte[] content = scaler.scaleImage(tempFile); String previousImage = (String)user.getAdditionalInfo(CmsUserIconHelper.USER_IMAGE_INFO); String newFileName = USER_IMAGE_FOLDER
if (!isDownScaleRequired(downScaler)) { int downHeight = downScaler.getHeight(); int downWidth = downScaler.getWidth(); int height = getHeight(); int width = getWidth(); downWidth = downScaler.getHeight(); return new CmsImageScaler(downScaler, downWidth, downHeight);
/** * 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(); } } } }
CmsImageScaler scaler = new CmsImageScaler(file.getContents(), file.getRootPath()); if (scaler.isValid()) { if (scaler.isDownScaleRequired(downScaler)) { scaler = scaler.getDownScaler(downScaler); false); if (prop.isNullProperty() || !prop.getValue().equals(scaler.toString())) { CmsPropertyDefinition.PROPERTY_IMAGE_SIZE, null, scaler.toString()); } else { prop.setResourceValue(scaler.toString()); Messages.get().container(Messages.RPT_IMAGE_SIZE_UPDATE_1, scaler.toString()), I_CmsReport.FORMAT_DEFAULT); Messages.get().container(Messages.RPT_IMAGE_SIZE_SKIP_1, scaler.toString()), I_CmsReport.FORMAT_DEFAULT);
if ((downScaler == null) || !isValid() || !downScaler.isValid()) { if (getPixelCount() < (downScaler.getPixelCount() / 2)) { int downWidth = downScaler.getWidth(); int downHeight = downScaler.getHeight(); if (downHeight > downWidth) { downHeight = downScaler.getWidth(); int height = getHeight(); int width = getWidth(); if (height > width) { height = getWidth();