public Object getNewValue(Object oldValue) throws Exception {
    _type = null;
    _height = null;
    _width = null;
    _size = null;

    String text = (String) oldValue;

    byte[] bytes = (byte[]) Base64.stringToObject(text);

    try {
      Image image = ImageLocalServiceUtil.getImage(bytes);

      _type = image.getType();
      _height = new Integer(image.getHeight());
      _width = new Integer(image.getWidth());
      _size = new Integer(image.getSize());
    } catch (Exception e) {
      if (_log.isWarnEnabled()) {
        String imageId = (String) _imageIdColumn.getOldValue();

        if (_log.isWarnEnabled()) {
          _log.warn("Unable to get image data for " + imageId + ": " + e.getMessage());
        }
      }

      _type = ImageConstants.TYPE_NOT_AVAILABLE;
      _height = null;
      _width = null;
      _size = new Integer(bytes.length);
    }

    return oldValue;
  }
  public Image updateImage(long imageId, InputStream is) throws PortalException, SystemException {

    Image image = getImage(is);

    return updateImage(
        imageId,
        image.getTextObj(),
        image.getType(),
        image.getHeight(),
        image.getWidth(),
        image.getSize());
  }
  protected byte[] getImageBytes(HttpServletRequest request, Image image) {
    try {
      if (!PropsValues.IMAGE_AUTO_SCALE) {
        return image.getTextObj();
      }

      ImageBag imageBag = null;

      if (image.getImageId() == 0) {
        imageBag = ImageToolUtil.read(image.getTextObj());

        RenderedImage renderedImage = imageBag.getRenderedImage();

        image.setHeight(renderedImage.getHeight());
        image.setWidth(renderedImage.getWidth());
      }

      int height = ParamUtil.getInteger(request, "height", image.getHeight());
      int width = ParamUtil.getInteger(request, "width", image.getWidth());

      if ((height >= image.getHeight()) && (width >= image.getWidth())) {
        return image.getTextObj();
      }

      if (image.getImageId() != 0) {
        imageBag = ImageToolUtil.read(image.getTextObj());
      }

      RenderedImage renderedImage = ImageToolUtil.scale(imageBag.getRenderedImage(), height, width);

      return ImageToolUtil.getBytes(renderedImage, imageBag.getType());
    } catch (Exception e) {
      if (_log.isWarnEnabled()) {
        _log.warn("Error scaling image " + image.getImageId(), e);
      }
    }

    return image.getTextObj();
  }
  protected Image getUserPortraitImageResized(Image image, long imageId)
      throws PortalException, SystemException {

    if (image == null) {
      return null;
    }

    if ((image.getHeight() > PropsValues.USERS_IMAGE_MAX_HEIGHT)
        || (image.getWidth() > PropsValues.USERS_IMAGE_MAX_WIDTH)) {

      User user = UserLocalServiceUtil.getUserByPortraitId(imageId);

      UserLocalServiceUtil.updatePortrait(user.getUserId(), image.getTextObj());

      return ImageLocalServiceUtil.getImage(imageId);
    }

    return image;
  }
  protected Image toUnwrappedModel(Image image) {
    if (image instanceof ImageImpl) {
      return image;
    }

    ImageImpl imageImpl = new ImageImpl();

    imageImpl.setNew(image.isNew());
    imageImpl.setPrimaryKey(image.getPrimaryKey());

    imageImpl.setImageId(image.getImageId());
    imageImpl.setModifiedDate(image.getModifiedDate());
    imageImpl.setText(image.getText());
    imageImpl.setType(image.getType());
    imageImpl.setHeight(image.getHeight());
    imageImpl.setWidth(image.getWidth());
    imageImpl.setSize(image.getSize());

    return imageImpl;
  }