I'm trying to wrap my head around futures, and have a little sample of scaling a directory of images going...
Can some explain to me how this should work?
import com.sksamuel.scrimage._
import scala.concurrent._
import ExecutionContext.Implicits.global
import java.io._
object Test {
def main(args: Array[String]) = {
val dir = new File("/Users/bthibault/Downloads/ff_images/")
dir.listFiles().foreach(file => AsyncImage(file).map( x => x.scale(0.5) ).onSuccess {
case image => image.writer(Format.PNG).withMaxCompression.write(file)
})
}
}
I'm using the Scrimage package https://github.com/sksamuel/scrimage/ where he gives an example of the Async operation... here is the actual Async file:
Can somebody help me understand what I need to do to get this working? I was playing with the map() function ... my thought was I need to return a real 'image' onSuccess rather than an AsyncImage ....