Search in sources :

Example 1 with ImageBag

use of com.liferay.portal.kernel.image.ImageBag in project liferay-ide by liferay.

the class WebServerServlet method getImageBytes.

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();
}
Also used : ImageBag(com.liferay.portal.kernel.image.ImageBag) RenderedImage(java.awt.image.RenderedImage) ServletException(javax.servlet.ServletException) RepositoryException(com.liferay.portal.kernel.repository.RepositoryException) NoSuchFileEntryException(com.liferay.portlet.documentlibrary.NoSuchFileEntryException) NoSuchFolderException(com.liferay.portlet.documentlibrary.NoSuchFolderException) PrincipalException(com.liferay.portal.security.auth.PrincipalException) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) IOException(java.io.IOException) NoSuchGroupException(com.liferay.portal.NoSuchGroupException)

Example 2 with ImageBag

use of com.liferay.portal.kernel.image.ImageBag in project liferay-ide by liferay.

the class UserLocalServiceImpl method updatePortrait.

/**
 * Updates the user's portrait image.
 *
 * @param  userId the primary key of the user
 * @param  bytes the new portrait image data
 * @return the user
 * @throws PortalException if a user with the primary key could not be found
 *         or if the new portrait was invalid
 * @throws SystemException if a system exception occurred
 */
@Override
public User updatePortrait(long userId, byte[] bytes) throws PortalException, SystemException {
    User user = userPersistence.findByPrimaryKey(userId);
    long imageMaxSize = PrefsPropsUtil.getLong(PropsKeys.USERS_IMAGE_MAX_SIZE);
    if ((imageMaxSize > 0) && ((bytes == null) || (bytes.length > imageMaxSize))) {
        throw new UserPortraitSizeException();
    }
    long portraitId = user.getPortraitId();
    if (portraitId <= 0) {
        portraitId = counterLocalService.increment();
        user.setPortraitId(portraitId);
    }
    try {
        ImageBag imageBag = ImageToolUtil.read(bytes);
        RenderedImage renderedImage = imageBag.getRenderedImage();
        if (renderedImage == null) {
            throw new UserPortraitTypeException();
        }
        renderedImage = ImageToolUtil.scale(renderedImage, PropsValues.USERS_IMAGE_MAX_HEIGHT, PropsValues.USERS_IMAGE_MAX_WIDTH);
        String contentType = imageBag.getType();
        imageLocalService.updateImage(portraitId, ImageToolUtil.getBytes(renderedImage, contentType));
    } catch (IOException ioe) {
        throw new ImageSizeException(ioe);
    }
    userPersistence.update(user);
    return user;
}
Also used : ImageBag(com.liferay.portal.kernel.image.ImageBag) User(com.liferay.portal.model.User) ImageSizeException(com.liferay.portlet.documentlibrary.ImageSizeException) UserPortraitTypeException(com.liferay.portal.UserPortraitTypeException) IOException(java.io.IOException) RenderedImage(java.awt.image.RenderedImage) UserPortraitSizeException(com.liferay.portal.UserPortraitSizeException)

Example 3 with ImageBag

use of com.liferay.portal.kernel.image.ImageBag in project liferay-ide by liferay.

the class DLPreviewableProcessor method storeThumbnailImages.

protected void storeThumbnailImages(FileVersion fileVersion, File file) throws Exception {
    ImageBag imageBag = ImageToolUtil.read(file);
    RenderedImage renderedImage = imageBag.getRenderedImage();
    storeThumbnailImages(fileVersion, renderedImage);
}
Also used : ImageBag(com.liferay.portal.kernel.image.ImageBag) RenderedImage(java.awt.image.RenderedImage)

Aggregations

ImageBag (com.liferay.portal.kernel.image.ImageBag)3 RenderedImage (java.awt.image.RenderedImage)3 IOException (java.io.IOException)2 NoSuchGroupException (com.liferay.portal.NoSuchGroupException)1 UserPortraitSizeException (com.liferay.portal.UserPortraitSizeException)1 UserPortraitTypeException (com.liferay.portal.UserPortraitTypeException)1 PortalException (com.liferay.portal.kernel.exception.PortalException)1 SystemException (com.liferay.portal.kernel.exception.SystemException)1 RepositoryException (com.liferay.portal.kernel.repository.RepositoryException)1 User (com.liferay.portal.model.User)1 PrincipalException (com.liferay.portal.security.auth.PrincipalException)1 ImageSizeException (com.liferay.portlet.documentlibrary.ImageSizeException)1 NoSuchFileEntryException (com.liferay.portlet.documentlibrary.NoSuchFileEntryException)1 NoSuchFolderException (com.liferay.portlet.documentlibrary.NoSuchFolderException)1 ServletException (javax.servlet.ServletException)1