Scala图像压缩和优化

时间:2015-12-04 14:04:34

标签: java scala jpeg scrimage

我一直在研究基于var mappedData = data.results.map(function(r) { var obj = {} obj["movie_id"] = data.id; obj["link"] = r.key return obj; }); 的图像压缩和优化库,https://github.com/sksamuel/scrimage看起来是一个不错的选择,直到我发现文档不正确并且没有得到他们的Gitter频道的任何支持

这是我的Scala/Java依赖行;

build.sbt

以及文档中的示例显示; https://github.com/sksamuel/scrimage/blame/master/README.md#L88

由于libraryDependencies += "com.sksamuel.scrimage" %% "scrimage-core" % "2.1.1"类中没有writer方法,因此似乎不正确。是否不再支持图书馆?有没有人为此找到解决方法?

1 个答案:

答案 0 :(得分:2)

这是一个关于如何读/写的简单示例。

  // bring in a writer into scope for later
  implicit val writer = PngWriter.NoCompression

  // the image.fromFile method will work out what the file type is, the ext is optional really
  val image = Image.fromFile(new File("input.jpeg"))

  // just playing about the with image. They are immutable.
  val modified = image.scale(2).brightness(1.2).flipY

  // output accepts a file, path, string etc and requires an implicit writer.
  val out = modified.output(new File("output.png"))