Skip to content
Snippets Groups Projects
Commit d57a60a4 authored by srosse's avatar srosse
Browse files

OO-1272: handle corrupted image which ImageIO cannot read

parent 0ba65ab1
No related branches found
No related tags found
No related merge requests found
......@@ -281,11 +281,13 @@ public class CourseLayoutGeneratorController extends FormBasicController {
private boolean processUploadedImage(File image){
int height = 0;
int width = 0;
String size[] = customCMgr.getImageSize(image);
int[] size = customCMgr.getImageSize(image);
if (size != null) {
width = Integer.parseInt(size[0]);
height = Integer.parseInt(size[1]);
} else return false;
width = size[0];
height = size[1];
} else {
return false;
}
// target file:
String fileType = logoUpl.getUploadFileName().substring(logoUpl.getUploadFileName().lastIndexOf("."));
VFSContainer base = (VFSContainer) courseEnvironment.getCourseBaseContainer().resolve(CourseLayoutHelper.LAYOUT_COURSE_SUBFOLDER);
......
......@@ -119,9 +119,11 @@ public class CustomConfigManager extends BasicManager {
sb.append("\tbackground-position: left top; \n");
sb.append("\tbackground-repeat: no-repeat; \n");
LocalFileImpl leaf = (LocalFileImpl) vfsItem;
String size[] = getImageSize(leaf.getBasefile());
sb.append("\twidth: ").append(size[0]).append("px; \n");
sb.append("\theight: ").append(size[1]).append("px; \n");
int[] size = getImageSize(leaf.getBasefile());
if(size != null) {
sb.append("\twidth: ").append(size[0]).append("px; \n")
.append("\theight: ").append(size[1]).append("px; \n");
}
sb.append("\tfloat: left; \n}\n");
sb.append("#o_logo { \n\t float: left; \n}");
}
......@@ -142,18 +144,22 @@ public class CustomConfigManager extends BasicManager {
* @param image
* @return array[width, height]
*/
public String[] getImageSize(File image){
public int[] getImageSize(File image){
int height = 0;
int width = 0;
try {
BufferedImage imageSrc = ImageIO.read(image);
height = imageSrc.getHeight();
width = imageSrc.getWidth();
if(imageSrc != null) {
height = imageSrc.getHeight();
width = imageSrc.getWidth();
} else {
return null;
}
} catch (IOException e) {
logError("Problem reading uploaded image", e);
return null;
}
return new String[] { String.valueOf(width), String.valueOf(height) };
return new int[] { width, height };
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment