private Thumbnail createThumbnail(InputStream originalFile, File thumbnailFile, int maxWidth, int maxHeight, long thumbId, String fileName) throws IOException, FileNotFoundException { // Load original image. Image originalImage = getImage(originalFile); // Create scaled buffered image from original image. BufferedImage scaledImage = scaleImage(originalImage, maxWidth, maxHeight); int height = scaledImage.getHeight(); int width = scaledImage.getWidth(); storeImage(scaledImage, thumbnailFile); return new Thumbnail(height, width, fileName, thumbId); }
private BufferedImage scaleImage(Image originalImage, int maxWidth, int maxHeight) { return scaleImage(originalImage, determineScaleSize(maxWidth, maxHeight, originalImage)); }
public CroppingAvatarImageDataProviderFactoryImpl(final AvatarTagger avatarTagger, final ImageScaler scaler) { this.scaler = scaler; thumber = new Thumber(); this.avatarTagger = avatarTagger; this.targetFormat = "png"; }
private Thumbnail createThumbnail(InputStream inputStream, File thumbnailFile, int maxWidth, int maxHeight, long thumbId, String fileName) throws IOException, ThumbnailRenderException { final BufferedImage thumbnailImage = scaleImage(maxWidth, maxHeight, inputStream); final int height = thumbnailImage.getHeight(); final int width = thumbnailImage.getWidth(); storeImage(thumbnailImage, thumbnailFile); return new Thumbnail(height, width, fileName, thumbId, mimeType); }
private AvatarImageDataProviderImpl(final InputStream uploadedImage, final Selection cropping) throws IOException { // rather should accept image? this.uploadedImage = thumber.getImage(uploadedImage); this.cropping = cropping; }
File processImage(final Avatar created, final InputStream imageData, final Selection croppingSelection, final ImageSize size) throws IOException { RenderedImage image = scaler.getSelectedImageData(new Thumber().getImage(imageData), croppingSelection, size.getPixels()); File file = createAvatarFile(created, size.getFilenameFlag()); avatarTagger.saveTaggedAvatar(image, AVATAR_IMAGE_FORMAT_FULL.getName(), file); eventPublisher.publish(new JiraHomeChangeEvent(JiraHomeChangeEvent.Action.FILE_ADD, JiraHomeChangeEvent.FileType.AVATAR, file)); return file; }
public BufferedImage scaleImage(int maxWidth, int maxHeight, InputStream imageStream) throws IOException { final ImageInputStream imageInputStream = ThumbnailUtil.getImageInputStream(imageStream); try { return scaleImage(maxWidth, maxHeight, imageInputStream); } finally { imageInputStream.close(); } }
try thumbnail = getThumbnail(thumbnailFile, fileName, thumbnailId); thumbnail = createThumbnail(originalFileStream, thumbnailFile, maxWidth, maxHeight, thumbnailId, fileName);
private WidthHeightHelper determineScaleSize(int maxWidth, int maxHeight, Image image) { return determineScaleSize(maxWidth, maxHeight, image.getWidth(null), image.getHeight(null)); }
public boolean isFileSupportedImage(File file) { try { return isFileSupportedImage(new FileInputStream(file)); } catch (FileNotFoundException e) { return false; } }
/** * Retrieves an existing thumbnail, or creates a new one. * * @param originalFile The file which is being thumbnailed. * @param thumbnailFile The location of the existing thumbnail (if it exists), or the location to create a new * thumbnail. * @param maxWidth The max width of the thumbnail. * @param maxHeight The max height of the thumbnail. */ public Thumbnail retrieveOrCreateThumbNail(File originalFile, File thumbnailFile, int maxWidth, int maxHeight, long thumbnailId) throws MalformedURLException { FileInputStream originalFileStream = null; try { originalFileStream = new FileInputStream(originalFile); return retrieveOrCreateThumbNail(originalFileStream, originalFile.getName(), thumbnailFile, maxWidth, maxHeight, thumbnailId); } catch (FileNotFoundException e) { log.error("Unable to create thumbnail: file not found: " + originalFile.getAbsolutePath()); } finally { IOUtils.closeQuietly(originalFileStream); } return null; }
public Image getImageFromFile(final File sourceFile) throws IOException { Image sourceImage = thumber.getImage(sourceFile, Predicates.<ReusableBufferedInputStream>alwaysTrue()); if (sourceImage == null) { throw new IOException("invalid image format: " + sourceFile.getName()); } return sourceImage; }
private BufferedImage scaleImage(int maxWidth, int maxHeight, ImageInputStream imageInputStream) throws IOException { final Optional<ImageReader> imageReader = ThumbnailUtil.getFirstImageReader(imageInputStream); if (!imageReader.isPresent()) { throw new IOException("Cannot read the image"); } final ImageReader reader = imageReader.get(); try { reader.setInput(imageInputStream); final ThumbnailDimension originalImageDimensions = new ThumbnailDimension(reader.getWidth(0), reader.getHeight(0)); final ThumbnailDimension scaledImageDimension = ThumbnailUtil.determineScaledDimensions(maxWidth, maxHeight, originalImageDimensions.getWidth(), originalImageDimensions.getHeight()); final int ratio = ThumbnailUtil.computeSubsamplingRatio(originalImageDimensions, scaledImageDimension, samplingFactor); final ImageReadParam param = reader.getDefaultReadParam(); param.setSourceSubsampling(ratio, ratio, 0, 0); final BufferedImage scaledImage = reader.read(0, param); //Subsampling does not return an exact size of an image - we need to resize it return scaleImage(scaledImage, scaledImageDimension); } finally { reader.dispose(); } }
Thumbnail thumbnail; try { thumbnail = getThumbnail(thumbnailFile, fileName, thumbnailId); } catch (IOException e) { log.error("Unable to get thumbnail image for id " + thumbnailId, e); thumbnail = createThumbnail(originalFileStream, thumbnailFile, maxWidth, maxHeight, thumbnailId, fileName); } catch (ThumbnailRenderException e) { log.error("Unable to create thumbnail image for id " + thumbnailId, e);
public boolean isFileSupportedImage(File file) { try { return isFileSupportedImage(new FileInputStream(file)); } catch (FileNotFoundException e) { return false; } }
return retrieveOrCreateThumbNail(originalFileStream, originalFile.getName(), thumbnailFile, maxWidth, maxHeight, thumbnailId);
public UploadedAvatar scaleImageToTempFile(final Image sourceImage, final File targetFile, final int edgeSize) throws IOException { ThumbnailDimension targetDimension = thumber.determineScaleSize(edgeSize, edgeSize, sourceImage.getWidth(null), sourceImage.getHeight(null)); BufferedImage scaledImage = thumber.scaleImage(sourceImage, targetDimension); ImageIO.write(scaledImage, AVATAR_IMAGE_FORMAT, targetFile); return new UploadedAvatar(targetFile, AVATAR_IMAGE_FORMAT_FULL.getContentType(), targetDimension.getWidth(), targetDimension.getHeight()); } }
private Thumbnail getThumbnail(File thumbnailFile, String filename, long thumbId) throws IOException { if (thumbnailFile.exists()) { final Image thumbImage = getImage(thumbnailFile, Predicates.<ReusableBufferedInputStream>alwaysTrue()); return new Thumbnail(thumbImage.getHeight(null), thumbImage.getWidth(null), filename, thumbId, mimeType); } return null; }
public ImageFileOperations() { this.thumber = new Thumber(); }
private ResultAndContentTypeChanged cropImageToFile(final int edgeSize, final Image sourceImage) { Result<File> prescaledFile = createTemporaryFile(TEMP_FILE_EXTENSION); if (!prescaledFile.isValid()) { return new ResultAndContentTypeChanged(prescaledFile, false); } ThumbnailDimension dimensions = thumber.determineScaleSize(edgeSize, edgeSize, sourceImage.getWidth(null), sourceImage.getHeight(null)); BufferedImage scaledImage = thumber.scaleImage(sourceImage, dimensions); try { ImageIO.write(scaledImage, AVATAR_IMAGE_FORMAT, prescaledFile.getResult()); return new ResultAndContentTypeChanged(prescaledFile, true); } catch (IOException e) { return new ResultAndContentTypeChanged(new Result<File>().addError(getText("avatarpicker.upload.temp.io", e.getMessage()), ErrorCollection.Reason.SERVER_ERROR), false); } }