|
|
@ -7,17 +7,24 @@ import java.io.File |
|
|
|
import com.sothr.imagetools.image.Image |
|
|
|
import com.sothr.imagetools.hash.HashService |
|
|
|
import javax.imageio.ImageIO |
|
|
|
import java.io.IOException |
|
|
|
|
|
|
|
object ImageService extends Logging { |
|
|
|
|
|
|
|
def getImage(file:File):Image = { |
|
|
|
val thumbnailPath = getThumbnailPath(file) |
|
|
|
val bufferedImage = ImageIO.read(file) |
|
|
|
val hashes = HashService.getImageHashes(bufferedImage, file.getAbsolutePath) |
|
|
|
val imageSize = { (bufferedImage.getWidth, bufferedImage.getHeight) } |
|
|
|
val image = new Image(file.getAbsolutePath, thumbnailPath, imageSize, hashes) |
|
|
|
debug(s"Created image: $image") |
|
|
|
image |
|
|
|
try { |
|
|
|
val thumbnailPath = getThumbnailPath(file) |
|
|
|
val bufferedImage = ImageIO.read(file) |
|
|
|
val hashes = HashService.getImageHashes(bufferedImage, file.getAbsolutePath) |
|
|
|
val imageSize = { (bufferedImage.getWidth, bufferedImage.getHeight) } |
|
|
|
val image = new Image(file.getAbsolutePath, thumbnailPath, imageSize, hashes) |
|
|
|
debug(s"Created 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 = { |
|
|
|