/** * Returns the Size which is exactly the same size as the given pixel edge value, rounding upward if no * exact match is available, except if the given value is greater than the maximum available size in which * case the maximum size will be returned. * * @param size * @return */ public static Size approx(final int size) { if (size >= largest.getPixels()) { return largest; } if (size <= orderedSizes.get(0).getPixels()) { return orderedSizes.get(0); } for (Size s : orderedSizes) { if (s.getPixels() >= size) { return s; } } // this shouldn't happen because we've exhausted the options return Size.defaultSize; } }
public Map<String, URI> getAvatarURLs(final ApplicationUser remoteUser, final Avatar avatar, final AvatarImageResolver avatarImageResolver) { Map<String, URI> uris = new HashMap<String, URI>(); for (AuiSize size : AuiSize.values()) { // TODO JRADEV-20790 - Don't output higher res URLs in our REST endpoints until we start using them ourselves. if (size.getSize() <= 48) { final Avatar.Size jiraSize = getSizeFromParam(size.name().toLowerCase()); final URI uri = avatarImageResolver.getAvatarAbsoluteUri(remoteUser, avatar, jiraSize); uris.put(format("%dx%d", size.getSize(), size.getSize()), uri); } } return uris; }
.add("avatarSize", avatarSize.getParam()) .add("defaultFullName", i18nHelper.getText("common.words.anonymous")) .add("fullname", fullName)
ImageSize availableSize = null; for (Avatar.Size size : Avatar.Size.inPixelOrder())
try for (Avatar.Size size : Avatar.Size.values())
/** * Returns the avatar URLs a user and a specific Avatar. * * @param avatarUser the user whose avatar this is (or null) * @param avatar the Avatar * @return avatar URLs mapped by size * @deprecated the notion of "all the avatar sizes" is broken. We plan to eventually scale to any reasonable pixel size. */ @Deprecated public static Map<String, URI> getAvatarURLs(ApplicationUser avatarUser, Avatar avatar) { final AvatarService avatarService = ComponentAccessor.getAvatarService(); final Map<String, URI> avatarUrls = new HashMap<String, URI>(); for (Avatar.Size size : Avatar.Size.values()) { final int px = size.getPixels(); if (px <= 48) // TODO JRADEV-20790 - Don't output higher res URLs in our REST endpoints until we start using them ourselves. { final String sizeName = String.format("%dx%d", px, px); avatarUrls.put(sizeName, avatarService.getAvatarUrlNoPermCheck(avatarUser, avatar, size)); } } return avatarUrls; } }
/** * Builds a URI for a JIRA avatar with the requested size. * * @param avatarUser the ApplicationUser whose avatar we'd like to display * @param avatar the Avatar whose URI we want * @param size the size in which the avatar should be displayed * @return a URI that can be used to display the avatar */ public URI getAvatarUrlNoPermCheck(final ApplicationUser avatarUser, final Avatar avatar, @Nonnull Size size) { final Long id = avatar.getId(); final String sizeName = size.getParam(); if (avatar.getAvatarType() == Avatar.Type.USER) { return URI.create(jiraAvatarSupport.get().getAvatarById(id, sizeName).getUrl()); } else { return getProjectAvatarUrl(avatar, size); } }
/** * @param pixelValue minimum number of pixels tall+wide the avatar size should be * @return an avatar {@link Size} that's equal to or larger than the pixelValue, * or null if there's no size that could cater the value. */ public static Size biggerThan(int pixelValue) { Size theSize = null; for (Size aSize : Size.inPixelOrder()) { if (aSize.pixels >= pixelValue) { theSize = aSize; break; } } return theSize; }
/** * @param pixelValue minimum number of pixels tall+wide the avatar size should be * @return an avatar {@link Size} that's equal to or larger than the {@link pixelValue}, * or null if there's no size that could cater the value. */ public static Size smallerThan(int pixelValue) { Size theSize = null; for (Size aSize : Lists.reverse(Size.inPixelOrder())) { if (aSize.pixels <= pixelValue) { theSize = aSize; break; } } return theSize; }
static List<Size> inPixelOrder() { if (null != orderedSizes) return orderedSizes; List<Size> orderedSizes = Arrays.asList(Size.values()); Collections.sort(orderedSizes, new Comparator<Size>() { @Override public int compare(final Size o1, final Size o2) { if (o1.getPixels() == o2.getPixels()) return 0; return (o1.getPixels() < o2.getPixels()) ? -1 : 1; } }); return orderedSizes; }
public static Map<String, String> getAvatarUrls(final Project project) { AvatarService avatarService = ComponentAccessor.getAvatarService(); final Avatar avatar = project.getAvatar(); if (avatar == null) return null; final Map<String, String> avatarUrls = new HashMap<String, String>(); for (Avatar.Size size : Avatar.Size.values()) { final int px = size.getPixels(); final String sizeName = String.format("%dx%d",px,px); if (px > 48) continue; // TODO JRADEV-20790 - Don't output higher res URLs in our REST endpoints until we start using them ourselves. avatarUrls.put(sizeName, avatarService.getProjectAvatarAbsoluteURL(project, size).toString()); } return avatarUrls; }
private Avatar.Size getValidAvatarSize(final HttpServletRequest request) { String avatarSizeSpec = request.getParameter(AVATAR_SIZE_PARAM); if (null == avatarSizeSpec) { return Avatar.Size.defaultSize(); } try { return Avatar.Size.getSizeFromParam(avatarSizeSpec); } catch( NoSuchElementException x ) { throw new IllegalArgumentException(AVATAR_SIZE_PARAM, x); } } }
private static String getAuiSizeName(final Avatar.Size size) { final int px = size.getPixels(); return format("%dx%d", px, px); } }
private static Map<String, String> getAvatarURLs(ApplicationUser user) { final AvatarService avatarService = ComponentAccessor.getAvatarService(); final Map<String, String> avatarUrls = new HashMap<String, String>(); for (Avatar.Size size : Avatar.Size.values()) { final int px = size.getPixels(); if (px > 48) continue; // TODO JRADEV-20790 - Don't output higher res URLs in our REST endpoints until we start using them ourselves. final String sizeName = String.format("%dx%d",px,px); // TODO this should be a URI reference and not an absolute URL avatarUrls.put(sizeName, avatarService.getAvatarAbsoluteURL(user, user, size).toString()); } return avatarUrls; }
private PNGTranscoder newPNGTranscoder(final Avatar.Size size) { final PNGTranscoder transcoder = createPngTranscoder(); transcoder.addTranscodingHint(PNGTranscoder.KEY_WIDTH, (float) size.getPixels()); transcoder.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, (float) size.getPixels()); return transcoder; } }
public int getPixels() { return size.getPixels(); }
@Override public String toString() { return size.toString(); } }
private boolean isCroppingNeeded(final UploadedAvatar image, final Avatar.Size targetSize) { final boolean isSquare = image.getHeight() == image.getWidth(); final boolean widthWithinBounds = image.getWidth() <= targetSize.getPixels(); return !widthWithinBounds || !isSquare; }