From 2f4f44232477dbf703e7a88f11be7a16d9f052ad Mon Sep 17 00:00:00 2001
From: Jan Sladek <Jan.Sladek@mni.thm.de>
Date: Fri, 13 Mar 2015 10:51:01 +0100
Subject: [PATCH] Fixed bug introduced in #15326. Now the thumbnail size is
 configurable in the .properties-file.

---
 src/main/java/de/thm/arsnova/ImageUtils.java | 58 ++++++++++----------
 1 file changed, 29 insertions(+), 29 deletions(-)

diff --git a/src/main/java/de/thm/arsnova/ImageUtils.java b/src/main/java/de/thm/arsnova/ImageUtils.java
index 5365e6d0c..b72c92621 100644
--- a/src/main/java/de/thm/arsnova/ImageUtils.java
+++ b/src/main/java/de/thm/arsnova/ImageUtils.java
@@ -45,28 +45,28 @@ public class ImageUtils {
 
 	// Or whatever size you want to read in at a time.
 	private static final int CHUNK_SIZE = 4096;
-	
+
 	/** Base64-Mimetype-Prefix start */
 	public static final String IMAGE_PREFIX_START = "data:image/";
-	
+
 	/** Base64-Mimetype-Prefix middle part */
 	public static final String IMAGE_PREFIX_MIDDLE = ";base64,";
-	
+
 	/* default value is 200 pixel in width, set the value in the configuration file */
 	private static int THUMB_WIDTH = 200;
 	/* default value is 200 pixel in height, set the value in the configuration file */
 	private static int THUMB_HEIGHT = 200;
-	
-	@Value(value = "{imageupload.thumbnail.width}")
+
+	@Value("${imageupload.thumbnail.width}")
 	public void setThumbWidth(int thumbWidth) {
 		ImageUtils.THUMB_WIDTH = thumbWidth;
 	}
-	
-	@Value(value = "{imageupload.thumbnail.height}")
+
+	@Value("${imageupload.thumbnail.height}")
 	public void setThumbHeight(int thumbHeight) {
 		ImageUtils.THUMB_HEIGHT = thumbHeight;
 	}
-	
+
 	private ImageUtils() {
 	}
 
@@ -98,23 +98,23 @@ public class ImageUtils {
 
 		return null;
 	}
-	
+
 	/**
 	 * Checks if a {@link String} starts with the Base64-Mimetype prefix.
-	 * 
-	 * @param maybeImage The Image as a base64 encoded {@link String} 
+	 *
+	 * @param maybeImage The Image as a base64 encoded {@link String}
 	 * @return true if the string is a potentially a base 64 encoded image.
 	 */
 	public static boolean isBase64EncodedImage(String maybeImage) {
 		return extractImageInfo(maybeImage) != null;
 	}
-	
+
 	/**
 	 * Extracts information(extension and the raw-image) from a {@link String}
 	 * representing a base64-encoded image and returns it as a two-dimensional
 	 * {@link String}-array, or null if the passed in {@link String} is not a
 	 * valid base64-encoded image.
-	 * 
+	 *
 	 * @param maybeImage
 	 *            a {@link String} representing a base64-encoded image.
 	 * @return two-dimensional {@link String}-array containing the information
@@ -134,9 +134,9 @@ public class ImageUtils {
 			else {
 				final int extensionStartIndex = IMAGE_PREFIX_START.length();
 				final int extensionEndIndex = maybeImage.indexOf(IMAGE_PREFIX_MIDDLE);
-				
+
 				final String imageWithoutPrefix = maybeImage.substring(extensionEndIndex);
-				
+
 				if (!imageWithoutPrefix.startsWith(IMAGE_PREFIX_MIDDLE)) {
 					return null;
 				}
@@ -144,19 +144,19 @@ public class ImageUtils {
 					final String[] imageInfo = new String[2];
 					final String extension = maybeImage.substring(extensionStartIndex, extensionEndIndex);
 					final String imageString = imageWithoutPrefix.substring(IMAGE_PREFIX_MIDDLE.length());
-					
+
 					imageInfo[0] = extension;
 					imageInfo[1] = imageString;
-					
+
 					return imageInfo;
 				}
 			}
 		}
 	}
-	
+
 	/**
 	 * Rescales an image represented by a Base64-encoded {@link String}
-	 * 
+	 *
 	 * @param originalImageString
 	 *            The original image represented by a Base64-encoded
 	 *            {@link String}
@@ -177,15 +177,15 @@ public class ImageUtils {
 			// imgInfo isn't null and contains two fields, this is checked by "isBase64EncodedImage"-Method
 			final String extension = imgInfo[0];
 			final String base64String = imgInfo[1];
-			
+
 			byte[] imageData = Base64.decodeBase64(base64String);
 			try {
 				BufferedImage originalImage = ImageIO.read(new ByteArrayInputStream(imageData));
 				BufferedImage newImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
 				Graphics2D g = newImage.createGraphics();
-				
+
 				final double ratio = ((double) originalImage.getWidth()) / ((double) originalImage.getHeight());
-				
+
 				int x = 0, y = 0, w = width, h = height;
 				if (originalImage.getWidth() > originalImage.getHeight()) {
 					final int newWidth = (int) Math.round((float) height * ratio);
@@ -198,20 +198,20 @@ public class ImageUtils {
 				}
 				g.drawImage(originalImage, x, y, w, h, null);
 				g.dispose();
-				
+
 				StringBuilder result = new StringBuilder();
 				result.append("data:image/");
 				result.append(extension);
 				result.append(";base64,");
-				
+
 				ByteArrayOutputStream output = new ByteArrayOutputStream();
 				ImageIO.write(newImage, extension, output);
-				
+
 				output.flush();
 				output.close();
-				
+
 				result.append(Base64.encodeBase64String(output.toByteArray()));
-				
+
 				return result.toString();
 			} catch (IOException e) {
 				LOGGER.error(e.getLocalizedMessage());
@@ -219,10 +219,10 @@ public class ImageUtils {
 			}
 		}
 	}
-	
+
 	/**
 	 * Generates a thumbnail image in the {@link Answer}, if none is present.
-	 * 
+	 *
 	 * @param answer
 	 *            the {@link Answer} where the thumbnail should be added.
 	 * @return true if the thumbnail image didn't exist before calling this
-- 
GitLab