From db247646dee2ad2c8e862c467f265dd0bf0dfd04 Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Wed, 3 Dec 2014 15:31:18 +0100 Subject: [PATCH] OO-1341; make the extension of the image mandatory, needed by the java scaling service to discover the type of the image --- .../java/org/olat/admin/layout/LogoMapper.java | 4 ++-- .../commons/services/image/ImageHelperBean.java | 5 ----- .../commons/services/image/ImageHelperSPI.java | 2 -- .../commons/services/image/ImageService.java | 4 +--- .../services/image/spi/ImageHelperImpl.java | 17 ++--------------- .../services/image/spi/ImageMagickHelper.java | 5 ----- .../org/olat/upgrade/OLATUpgrade_8_4_0.java | 2 +- .../org/olat/user/DisplayPortraitManager.java | 13 +++++++++---- .../org/olat/user/ProfileFormController.java | 3 ++- .../org/olat/user/restapi/UserWebService.java | 3 ++- 10 files changed, 19 insertions(+), 39 deletions(-) diff --git a/src/main/java/org/olat/admin/layout/LogoMapper.java b/src/main/java/org/olat/admin/layout/LogoMapper.java index b4e47ecc282..e1b922f8003 100644 --- a/src/main/java/org/olat/admin/layout/LogoMapper.java +++ b/src/main/java/org/olat/admin/layout/LogoMapper.java @@ -52,9 +52,9 @@ class LogoMapper implements Mapper { if(lastModified < logo.lastModified() || !scaledLogo.exists()) { ImageService imageService = CoreSpringFactory.getImpl(ImageService.class); File logo1x = new File(dir, "oo-logo@1x.png"); - imageService.scaleImage(logo, logo1x, 104, 50); + imageService.scaleImage(logo, "png", logo1x, 104, 50); File logo2x = new File(dir, "oo-logo@2x.png"); - imageService.scaleImage(logo, logo2x, 208, 50); + imageService.scaleImage(logo, "png", logo2x, 208, 50); } return new FileMediaResource(scaledLogo); } diff --git a/src/main/java/org/olat/core/commons/services/image/ImageHelperBean.java b/src/main/java/org/olat/core/commons/services/image/ImageHelperBean.java index c03d9101102..f6878825002 100644 --- a/src/main/java/org/olat/core/commons/services/image/ImageHelperBean.java +++ b/src/main/java/org/olat/core/commons/services/image/ImageHelperBean.java @@ -54,11 +54,6 @@ public class ImageHelperBean implements ImageService { return imageHelperServiceProvider.cropImage(image, cropedImage, cropSelection); } - @Override - public Size scaleImage(File image, File scaledImage, int maxWidth, int maxHeight) { - return imageHelperServiceProvider.scaleImage(image, scaledImage, maxWidth, maxHeight); - } - @Override public Size scaleImage(File image, String extension, File scaledImage, int maxWidth, int maxHeight) { return imageHelperServiceProvider.scaleImage(image, extension, scaledImage, maxWidth, maxHeight); diff --git a/src/main/java/org/olat/core/commons/services/image/ImageHelperSPI.java b/src/main/java/org/olat/core/commons/services/image/ImageHelperSPI.java index d0cb769e599..881774f35f3 100644 --- a/src/main/java/org/olat/core/commons/services/image/ImageHelperSPI.java +++ b/src/main/java/org/olat/core/commons/services/image/ImageHelperSPI.java @@ -45,8 +45,6 @@ public interface ImageHelperSPI { public boolean cropImage(File image, File cropedImage, Crop cropSelection); - public Size scaleImage(File image, File scaledImage, int maxWidth, int maxHeight); - public Size scaleImage(File image, String extension, File scaledImage, int maxWidth, int maxHeight); public Size scaleImage(VFSLeaf image, VFSLeaf scaledImage, int maxWidth, int maxHeight, boolean fill); diff --git a/src/main/java/org/olat/core/commons/services/image/ImageService.java b/src/main/java/org/olat/core/commons/services/image/ImageService.java index cf14ab77fa1..14e6831151b 100644 --- a/src/main/java/org/olat/core/commons/services/image/ImageService.java +++ b/src/main/java/org/olat/core/commons/services/image/ImageService.java @@ -40,9 +40,7 @@ public interface ImageService { public Size getSize(VFSLeaf image, String suffix); public boolean cropImage(File image, File cropedImage, Crop cropSelection); - - public Size scaleImage(File image, File scaledImage, int maxWidth, int maxHeight); - + public Size scaleImage(File image, String extension, File scaledImage, int maxWidth, int maxHeight); public Size scaleImage(VFSLeaf image, VFSLeaf scaledImage, int maxWidth, int maxHeight, boolean fill); diff --git a/src/main/java/org/olat/core/commons/services/image/spi/ImageHelperImpl.java b/src/main/java/org/olat/core/commons/services/image/spi/ImageHelperImpl.java index 08fbfbac79c..94ac8f8dbf5 100644 --- a/src/main/java/org/olat/core/commons/services/image/spi/ImageHelperImpl.java +++ b/src/main/java/org/olat/core/commons/services/image/spi/ImageHelperImpl.java @@ -286,21 +286,8 @@ public class ImageHelperImpl extends AbstractImageHelper { } /** - * @param image the image to scale - * @param scaledImaged the new scaled image - * @param maxWidth the maximum width of the new scaled image - * @param maxheight the maximum height of the new scaled image - * @return - */ - @Override - public Size scaleImage(File image, File scaledImage, int maxWidth, int maxHeight) { - String extension = FileUtils.getFileSuffix(image.getName()); - return scaleImage(image, extension, scaledImage, maxWidth, maxHeight); - } - - /** - * @param image the image to scale - * @param image extension if not given by the image file (optional) + * @param image The image to scale + * @param imageExt The extension if not given by the image file (optional) * @param scaledImaged the new scaled image * @param maxWidth the maximum width of the new scaled image * @param maxheight the maximum height of the new scaled image diff --git a/src/main/java/org/olat/core/commons/services/image/spi/ImageMagickHelper.java b/src/main/java/org/olat/core/commons/services/image/spi/ImageMagickHelper.java index b8e7a511e2d..6657b645f33 100644 --- a/src/main/java/org/olat/core/commons/services/image/spi/ImageMagickHelper.java +++ b/src/main/java/org/olat/core/commons/services/image/spi/ImageMagickHelper.java @@ -88,11 +88,6 @@ public class ImageMagickHelper extends AbstractImageHelper { @Override public Size scaleImage(File image, String extension, File scaledImage, int maxWidth, int maxHeight) { - return scaleImage(image, scaledImage, maxWidth, maxHeight); - } - - @Override - public Size scaleImage(File image, File scaledImage, int maxWidth, int maxHeight) { FinalSize finalSize = generateThumbnail(image, scaledImage, false, maxWidth, maxHeight, false); if(finalSize != null) { return new Size(finalSize.getWidth(), finalSize.getHeight(), true); diff --git a/src/main/java/org/olat/upgrade/OLATUpgrade_8_4_0.java b/src/main/java/org/olat/upgrade/OLATUpgrade_8_4_0.java index 4d30fc598c7..e78d01dc1db 100644 --- a/src/main/java/org/olat/upgrade/OLATUpgrade_8_4_0.java +++ b/src/main/java/org/olat/upgrade/OLATUpgrade_8_4_0.java @@ -187,7 +187,7 @@ public class OLATUpgrade_8_4_0 extends OLATUpgrade { extension = "png"; } File pSmallFile = new File(portraitDir, "portrait_small" + "." + extension); - imageHelper.scaleImage(file, pSmallFile, DisplayPortraitManager.WIDTH_PORTRAIT_SMALL, DisplayPortraitManager.WIDTH_PORTRAIT_SMALL); + imageHelper.scaleImage(file, extension, pSmallFile, DisplayPortraitManager.WIDTH_PORTRAIT_SMALL, DisplayPortraitManager.WIDTH_PORTRAIT_SMALL); counter++; break; } diff --git a/src/main/java/org/olat/user/DisplayPortraitManager.java b/src/main/java/org/olat/user/DisplayPortraitManager.java index 452be1c5f3f..e4c5f4e3c28 100644 --- a/src/main/java/org/olat/user/DisplayPortraitManager.java +++ b/src/main/java/org/olat/user/DisplayPortraitManager.java @@ -146,7 +146,7 @@ public class DisplayPortraitManager extends BasicManager implements UserDataDele return null; } - public void setPortrait(File file, String username) { + public void setPortrait(File file, String filename, String username) { //first remove old ones File portraitDir = getPortraitDir(username); if(portraitDir != null) { @@ -160,14 +160,19 @@ public class DisplayPortraitManager extends BasicManager implements UserDataDele String extension = FileUtils.getFileSuffix(file.getName()); if(!StringHelper.containsNonWhitespace(extension)) { - extension = "png"; + if(StringHelper.containsNonWhitespace(filename)) { + extension = FileUtils.getFileSuffix(filename); + } + if(!StringHelper.containsNonWhitespace(extension)) { + extension = "png"; + } } File pBigFile = new File(portraitDir, DisplayPortraitManager.PORTRAIT_BIG_FILENAME + "." + extension); File pSmallFile = new File(portraitDir, DisplayPortraitManager.PORTRAIT_SMALL_FILENAME + "." + extension); ImageService imageHelper = CoreSpringFactory.getImpl(ImageService.class); - Size size = imageHelper.scaleImage(file, pBigFile, DisplayPortraitManager.WIDTH_PORTRAIT_BIG, DisplayPortraitManager.WIDTH_PORTRAIT_BIG); + Size size = imageHelper.scaleImage(file, extension, pBigFile, DisplayPortraitManager.WIDTH_PORTRAIT_BIG, DisplayPortraitManager.WIDTH_PORTRAIT_BIG); if(size != null){ - size = imageHelper.scaleImage(file, pSmallFile, DisplayPortraitManager.WIDTH_PORTRAIT_SMALL, DisplayPortraitManager.WIDTH_PORTRAIT_SMALL); + size = imageHelper.scaleImage(file, extension, pSmallFile, DisplayPortraitManager.WIDTH_PORTRAIT_SMALL, DisplayPortraitManager.WIDTH_PORTRAIT_SMALL); } } diff --git a/src/main/java/org/olat/user/ProfileFormController.java b/src/main/java/org/olat/user/ProfileFormController.java index 03cb6447506..31193b2b563 100644 --- a/src/main/java/org/olat/user/ProfileFormController.java +++ b/src/main/java/org/olat/user/ProfileFormController.java @@ -395,8 +395,9 @@ public class ProfileFormController extends FormBasicController { } File uploadedImage = portraitUpload.getUploadFile(); + String uploadedFilename = portraitUpload.getUploadFileName(); if(uploadedImage != null) { - dps.setPortrait(uploadedImage, identityToModify.getName()); + dps.setPortrait(uploadedImage, uploadedFilename, identityToModify.getName()); } // Store the "about me" text. diff --git a/src/main/java/org/olat/user/restapi/UserWebService.java b/src/main/java/org/olat/user/restapi/UserWebService.java index 479a0c37d3c..11577958153 100644 --- a/src/main/java/org/olat/user/restapi/UserWebService.java +++ b/src/main/java/org/olat/user/restapi/UserWebService.java @@ -579,7 +579,8 @@ public class UserWebService { } partsReader = new MultipartReader(request); File tmpFile = partsReader.getFile(); - DisplayPortraitManager.getInstance().setPortrait(tmpFile, identity.getName()); + String filename = partsReader.getFilename(); + DisplayPortraitManager.getInstance().setPortrait(tmpFile, filename, identity.getName()); return Response.ok().build(); } catch (Throwable e) { throw new WebApplicationException(e); -- GitLab