From 9a4add44ecbd32dea6ac3d30fd81ae1ac82e3dbc Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 15 Oct 2017 05:37:18 +0300 Subject: api: ImagesService --- .../com/juick/server/configuration/BaseWebConfiguration.java | 9 +++++++++ .../src/main/java/com/juick/server/util/ImageUtils.java | 10 ++++++++++ 2 files changed, 19 insertions(+) (limited to 'juick-server-web/src/main/java/com/juick/server') diff --git a/juick-server-web/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java b/juick-server-web/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java index a2422df9..efbe66cb 100644 --- a/juick-server-web/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java +++ b/juick-server-web/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java @@ -21,8 +21,12 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import com.juick.configuration.DataConfiguration; +import com.juick.service.ImagesService; +import com.juick.service.ImagesServiceImpl; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.multipart.MultipartResolver; @@ -35,6 +39,7 @@ import java.util.List; /** * Created by vitalyster on 28.06.2016. */ +@Import(DataConfiguration.class) @Configuration public class BaseWebConfiguration implements WebMvcConfigurer { @@ -67,4 +72,8 @@ public class BaseWebConfiguration implements WebMvcConfigurer { resolver.setMaxUploadSize(10000000); return resolver; } + @Bean + public ImagesService imagesService() { + return new ImagesServiceImpl(); + } } diff --git a/juick-server-web/src/main/java/com/juick/server/util/ImageUtils.java b/juick-server-web/src/main/java/com/juick/server/util/ImageUtils.java index 25345439..7f21c0a5 100644 --- a/juick-server-web/src/main/java/com/juick/server/util/ImageUtils.java +++ b/juick-server-web/src/main/java/com/juick/server/util/ImageUtils.java @@ -18,6 +18,7 @@ package com.juick.server.util; +import org.apache.commons.imaging.ImageInfo; import org.apache.commons.io.FilenameUtils; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.Imaging; @@ -149,4 +150,13 @@ public class ImageUtils { ImageIO.write(Scalr.resize(originalImage, 96), targetExt, Paths.get(imgDir, "a", targetName).toFile()); ImageIO.write(Scalr.resize(originalImage, 32), targetExt, Paths.get(imgDir, "as", targetName).toFile()); } + + public static Integer getImageHeight(File imageFile) throws IOException, ImageReadException { + ImageInfo info = Imaging.getImageInfo(imageFile); + return info.getHeight(); + } + public static Integer getImageWidth(File imageFile) throws IOException, ImageReadException { + ImageInfo info = Imaging.getImageInfo(imageFile); + return info.getWidth(); + } } \ No newline at end of file -- cgit v1.2.3