forked from gotson/komga
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: get images dimension during media analysis
media analysis will get width and height for each image in a book this is required for gotson#123
- Loading branch information
Showing
13 changed files
with
123 additions
and
25 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
komga/src/flyway/resources/db/migration/sqlite/V20200730135746__image_dimension.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
alter table media_page | ||
add column width int NULL; | ||
alter table media_page | ||
add column height int NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
komga/src/main/kotlin/org/gotson/komga/domain/model/Dimension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.gotson.komga.domain.model | ||
|
||
data class Dimension( | ||
val width: Int, | ||
val height: Int | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
komga/src/main/kotlin/org/gotson/komga/infrastructure/image/ImageAnalyzer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.gotson.komga.infrastructure.image | ||
|
||
import mu.KotlinLogging | ||
import org.gotson.komga.domain.model.Dimension | ||
import org.springframework.stereotype.Service | ||
import java.io.InputStream | ||
import javax.imageio.ImageIO | ||
|
||
private val logger = KotlinLogging.logger {} | ||
|
||
@Service | ||
class ImageAnalyzer { | ||
|
||
fun getDimension(stream: InputStream): Dimension? = | ||
stream.use { | ||
ImageIO.createImageInputStream(stream).use { fis -> | ||
val readers = ImageIO.getImageReaders(fis) | ||
if (readers.hasNext()) { | ||
val reader = readers.next() | ||
reader.input = fis | ||
Dimension(reader.getWidth(0), reader.getHeight(0)) | ||
} else { | ||
logger.warn { "no reader found" } | ||
null | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters