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();
}
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;
}
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);
}
Aggregations