Skip to content

Instantly share code, notes, and snippets.

@beranradek
Created June 5, 2013 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beranradek/5717712 to your computer and use it in GitHub Desktop.
Save beranradek/5717712 to your computer and use it in GitHub Desktop.
package com.examples.img
import java.io.File
import scala.sys.process._
class ImageMagickConverter(convertExec: String) {
def resizeImage(in: File, out: File, width: Int, height: Int, quality: Int = ImageMagickConverter.DefaultQuality): Boolean = {
val qual = if (quality < 0) ImageMagickConverter.DefaultQuality else if (quality > 100) 100 else quality
val inAbsPath = in.getAbsolutePath()
val outAbsPath = out.getAbsolutePath()
val cmd = s"${convertExec} -geometry ${width}x${height} -quality ${qual} ${inAbsPath} ${outAbsPath}"
val exitCode = cmd.!
exitCode == 0
}
}
object ImageMagickConverter {
val DefaultQuality = 80
def main(args: Array[String]) {
println(new ImageMagickConverter("""c:\programy\portable\ImageMagick-6.8.5-10\convert.exe""")
.resizeImage(new File("""c:\Radek\obrazky\conectarok_1328754878_49.jpg"""),
new File("""c:\Radek\obrazky\conectarok_1328754878_49-out.jpg"""), 336, 210))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment