/** * Find the largest square that fits inside the destination image. * * @param imageWidth original image width. * @param imageHeight original image height. * @param targetSize the size of the destination avatar. * @return description of where to crop a square out of that image. */ private Selection autoCalculateImageCropSelection(int imageWidth, int imageHeight, int targetSize) { if (imageWidth <= targetSize && imageHeight <= targetSize) { return new Selection(0, 0, imageWidth, imageHeight); } // Find the largest square that can be entirely filled by the source image that is no // smaller than the final image. int largestSquareWidth = Math.min(imageWidth, imageHeight); // Centre that bounding square on the source image. The selection is all of the image // that falls inside the square. int xOffset = (imageWidth - largestSquareWidth) / 2; int yOffset = (imageHeight - largestSquareWidth) / 2; //noinspection SuspiciousNameCombination return new Selection(xOffset, yOffset, largestSquareWidth, largestSquareWidth); }
ImageSize(Avatar.Size size) { this.size = size; this.filenameFlag = Assertions.notNull("filenameFlag", (size.isDefault ? "" : size.param + "_")); this.originSelection = new Selection(0, 0, getPixels(), getPixels()); }
public Response cropTemporaryAvatar(final Avatar.Type type, final String ownerId, final AvatarCroppingBean croppingInstructions) { Selection selection = new Selection(croppingInstructions.getCropperOffsetX(), croppingInstructions.getCropperOffsetY(), croppingInstructions.getCropperWidth(), croppingInstructions.getCropperWidth()); AvatarPickerHelperImpl.Result<AvatarPickerHelperImpl.TemporaryAvatarBean> cropResult = avatarPickerHelper .cropTemporary(ownerId, type, selection); if (!cropResult.isValid()) { throwWebException(cropResult.getErrorCollection()); } return Response.status(Response.Status.OK).cacheControl(never()).build(); }
public AvatarBean createAvatarFromTemporary(final ApplicationUser remoteUser, final Avatar.Type type, final String ownerId, final AvatarCroppingBean croppingInstructions) { Selection selection = new Selection(croppingInstructions.getCropperOffsetX(), croppingInstructions.getCropperOffsetY(), croppingInstructions.getCropperWidth(), croppingInstructions.getCropperWidth()); Avatar conversionResult = convertTemporaryToReal(remoteUser, ownerId, type, selection); final AvatarBean avatarBean = AvatarBeanFactory.createAvatarBean(conversionResult); return avatarBean; }
Selection selection = new Selection(croppingInstructions.getCropperOffsetX(), croppingInstructions.getCropperOffsetY(), croppingInstructions.getCropperWidth(), croppingInstructions.getCropperWidth());
Selection selection = new Selection(temporaryAvatarBean.getCropperOffsetX(), temporaryAvatarBean.getCropperOffsetY(), temporaryAvatarBean.getCropperWidth(), temporaryAvatarBean.getCropperWidth());