|
@ -7,17 +7,24 @@ import java.io.File |
|
|
import com.sothr.imagetools.image.Image |
|
|
import com.sothr.imagetools.image.Image |
|
|
import com.sothr.imagetools.hash.HashService |
|
|
import com.sothr.imagetools.hash.HashService |
|
|
import javax.imageio.ImageIO |
|
|
import javax.imageio.ImageIO |
|
|
|
|
|
import java.io.IOException |
|
|
|
|
|
|
|
|
object ImageService extends Logging { |
|
|
object ImageService extends Logging { |
|
|
|
|
|
|
|
|
def getImage(file:File):Image = { |
|
|
def getImage(file:File):Image = { |
|
|
|
|
|
try { |
|
|
val thumbnailPath = getThumbnailPath(file) |
|
|
val thumbnailPath = getThumbnailPath(file) |
|
|
val bufferedImage = ImageIO.read(file) |
|
|
val bufferedImage = ImageIO.read(file) |
|
|
val hashes = HashService.getImageHashes(bufferedImage, file.getAbsolutePath) |
|
|
val hashes = HashService.getImageHashes(bufferedImage, file.getAbsolutePath) |
|
|
val imageSize = { (bufferedImage.getWidth, bufferedImage.getHeight) } |
|
|
val imageSize = { (bufferedImage.getWidth, bufferedImage.getHeight) } |
|
|
val image = new Image(file.getAbsolutePath, thumbnailPath, imageSize, hashes) |
|
|
val image = new Image(file.getAbsolutePath, thumbnailPath, imageSize, hashes) |
|
|
debug(s"Created image: $image") |
|
|
debug(s"Created image: $image") |
|
|
image |
|
|
|
|
|
|
|
|
return image |
|
|
|
|
|
} catch { |
|
|
|
|
|
case ioe:IOException => error(s"Error processing ${file.getAbsolutePath}", ioe) |
|
|
|
|
|
case ex:Exception => error(s"Error processing ${file.getAbsolutePath}", ex) |
|
|
|
|
|
} |
|
|
|
|
|
null |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
def getThumbnailPath(file:File):String = { |
|
|
def getThumbnailPath(file:File):String = { |
|
|