coobird / thumbnailator

Thumbnailator - a thumbnail generation library for Java
MIT License
5.14k stars 784 forks source link

Slow zoom #142

Open salamanders opened 5 years ago

salamanders commented 5 years ago

I'd like to create a "slow zoom to center of photo" BufferedImage sequence, and I think this library can do it without using external hacks, but when I tried, it came out all janky.

val scaled =
        Canvas(maxRes.width, maxRes.height, Positions.CENTER).apply(
                Thumbnails.of(file)
                        .size(maxRes.width, maxRes.height)
                        .asBufferedImage())

for (i in 0 until maxFrames) {
    // not proportional :/
    val trimmed = scaled.getSubimage(i, i, scaled.width - (2 * i), scaled.height - (2 * i))
    var t = Thumbnails.of(trimmed).size(maxRes.width, maxRes.height)
    if (orientation != 0) {
        t = t.rotate(orientation.toDouble())
    }
    yield(t.asBufferedImage())
}

Is there a better way to do the Canvas trim and a proportional edge-trim as the frames progress? I've got the two Thumbnails.of which smells wrong, and I know the 2 * i doesn't respect the image ratio, so... ya. But I'm hopeful because I just found out about Canvas. Not sure how to incorporate it into ThumbnailBuilder chain yet, but still looking!