sksamuel / scrimage Goto Github PK
View Code? Open in Web Editor NEWJVM - Java, Kotlin, Scala image processing library
Home Page: https://sksamuel.github.io/scrimage
License: Apache License 2.0
JVM - Java, Kotlin, Scala image processing library
Home Page: https://sksamuel.github.io/scrimage
License: Apache License 2.0
I use Thumbnails,it set resize start position(x,y)
Thumbnails.of("d:\tmp\rest.jpg")
.size(320, 200).sourceRegion(10,40, 320, 200)
.outputQuality(1f)
.toFile(new File("d:\tmp\rest3.jpg"));
Scrimage i see code Position is not use.
def resizeTo(targetWidth: Int, targetHeight: Int, position: Position = Center): Image = {
val target = Image.empty(targetWidth, targetHeight)
val g2 = target.awt.getGraphics.asInstanceOf[Graphics2D]
g2.drawImage(awt, 0, 0, null)
g2.dispose()
target
}
why?
I want use jcrop user avatar!
Thanks!
Given this icon, which has a transparent background:
(it only seems white on top of github's white background)
And this image:
When I compose the icon over the image, I would expect to see this:
But instead I see this:
(note, again, that the rectangle surrounding the icon is transparent; you are seeing through the resulting image into the page's background)
This is the code I used:
val pic = Image(new File("picture.jpg"))
val icon = Image(new File("icon.png"))
def combineImages(composite: Composite, targetPath: String) = {
val result = pic.composite(composite, icon)
result.writer(Format.PNG).withCompression(9).write(new File(targetPath))
}
combineImages(new NormalComposite(1.0), "result_normal_1.0.png")
It seems that the pixels from the incoming (second / icon) image are being taken "absolutely", replacing the pixels on the target (first / picture) image.
Each pixel should be combined not only taking into account the alpha parameter given to the composite object, but the transparency of each individual pixel.
For a reference implementation, compare with gimp (which was used to generate the "expected" result)
It is eventually the pixels method which throw this error. I have loaded a PNG image.
java.lang.UnsupportedOperationException
at com.sksamuel.scrimage.Image.pixels(Image.scala:311)
at com.sksamuel.scrimage.Image.imageState(Image.scala:675)
at com.sksamuel.scrimage.Image.equals(Image.scala:683)
at util.ResizeImages$.consoleTest(OneTimers.scala:26)
Code in ResizeImages.consoleTest()
println("!" + image == imageWithoutTransparency)
println("!" + image.equals(imageWithoutTransparency))
Currently, I'm using the Image class to load and resize an image on demand at an endpoint in my app. At present I am showing execution times of about a half a second for any I/O operation on (input from File
, output to ByteArrayOutputStream
). I am curious if there is anything I am doing wrong or if you are aware of a bottleneck under the hood.
Response code logic is from Unfiltered, and the ResponseBytes
method merely outputs the contents of the bytearray to the client.
Code is as follows. I removed the resizing logic for simplicity while working this out and the benchmark did not change.
A similar process using javax.imageio completes in roughly .06 of a second.
var img = time Image(new File("/Users/uid/Pictures/D265.jpg"))
val output = new ByteArrayOutputStream(1024*8)
img.write(output)
output.flush()
Ok ~> ResponseHeader("Content-type",Set("image/jpeg")) ~> ResponseBytes(output.toByteArray())
Any help, as ever, greatly appreciated ๐
I'm running into a conflict with the logger dependency included with scrimage. Specifically:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/jim/.ivy2/cache/org.slf4j/slf4j-log4j12/jars/slf4j-log4j12-1.6.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/jim/.ivy2/cache/ch.qos.logback/logback-classic/jars/logback-classic-1.0.13.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
The note at the url is relevant:
Embedded components such as libraries or frameworks should not declare a dependency on any SLF4J binding but only depend on slf4j-api. When a library declares a compile-time dependency on a SLF4J binding, it imposes that binding on the end-user, thus negating SLF4J's purpose. When you come across an embedded component declaring a compile-time dependency on any SLF4J binding, please take the time to contact the authors of said component/library and kindly ask them to mend their ways.
I have about 2 weeks experience with Scala so I may be missing something but thought I'd drop this note here, just in case.
Also, just want to say that scrimage is an awesome project and easy to work with. Thank you!
EDIT Going with the solution here for a quick-fix: http://stackoverflow.com/questions/10958215/how-to-exclude-commons-logging-from-a-scala-sbt-slf4j-project
Oct 02, 2013 1:11:51 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [mvc] in context with path [] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: Error doing rescale. Target size was 0x64 but must be at least 3x3.] with root cause
java.lang.RuntimeException: Error doing rescale. Target size was 0x64 but must be at least 3x3.
at thirdparty.mortennobel.ResampleOp.doFilter(ResampleOp.java:93)
at thirdparty.mortennobel.AdvancedResizeOp.filter(AdvancedResizeOp.java:40)
at com.sksamuel.scrimage.Image.scaleTo(Image.scala:373)
at com.sksamuel.scrimage.Image.fit(Image.scala:296)
at com.cloudray.scalapress.media.ThumbnailService._resize(ThumbnailService.scala:90)
at com.cloudray.scalapress.media.ThumbnailService$$anonfun$_generate$1.apply(ThumbnailService.scala:84)
at com.cloudray.scalapress.media.ThumbnailService$$anonfun$_generate$1.apply(ThumbnailService.scala:84)
at scala.Option.map(Option.scala:145)
at com.cloudray.scalapress.media.ThumbnailService._generate(ThumbnailService.scala:84)
at com.cloudray.scalapress.media.ThumbnailService.thumbnail(ThumbnailService.scala:62)
at com.cloudray.scalapress.media.ImageController.imageResized(ImageController.scala:49)
at sun.reflect.GeneratedMethodAccessor766.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
When I use the scale function the images shift 1 pixel to the left-top. For example even if an image is scaled with 1.0 value it becomes different than the original image. Here is an example with the original.jpg and scaled.jpg The first image is the scaled one and the second is the original one. If you open them in different tabs and switch from one to other you will realize the shift at the upper left corner, but you have to look carefully.
there is a certain image that can not be converted to BufferedImage (always throw exception from line 720). I am sure the inputstream is not null. Here is the test code
import scala.language.postfixOps
import java.net.{HttpURLConnection, URL}
import java.io.BufferedInputStream
import com.sksamuel.scrimage.Image
object ScrimageTest extends Processor {
def main(args: Array[String]) {
testFail()
testPass()
}
def testFail() {
try {
val image = download("http://i.imgur.com/94N42vd.jpg")
val width = Image(image).width
val height = Image(image).height
println("will not get here")
} catch {
case e: Exception =>
println(e.getStackTraceString)
}
// javax.imageio.spi.FilterIterator.next(ServiceRegistry.java:825)
// javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:528)
// javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:513)
// com.sksamuel.scrimage.Image$.apply(Image.scala:725)
// com.sksamuel.scrimage.Image$.apply(Image.scala:710)
}
def testPass() {
val image = download("http://i.imgur.com/qahD2Py.png")
val width = Image(image).width
val height = Image(image).height
println(s"width: $width, height: $height")
}
def download(source_url: String): Array[Byte] = {
val source = new URL(source_url)
val conn = source.openConnection().asInstanceOf[HttpURLConnection]
conn.connect()
val stream = new BufferedInputStream(conn.getInputStream)
Stream.continually(stream.read).takeWhile(-1 !=).map(_.toByte).toArray
}
}
I've been doing some profiling to improve the performance of our imageserver (https://github.com/rdio/thor) and I noticed that this line is taking about 150ms:
I don't have much familiarity with these APIs, is there anything I can do to reduce the impact here? Image scaling, filters, overlays, etc. are all together taking < 50ms on a 1200x1200 image. It seems unfortunate that after all of that getting the bytes to send in a Finagle response would be the biggest performance hit.
EDIT: Version: "com.sksamuel.scrimage" % "scrimage-core_2.10" % "1.3.5" exclude("org.slf4j", "slf4j-log4j12"),
I am trying to put watermarks on the images. I have tried half of the composite types but could not get the result I wanted. Composite combines the images but both images just appear faded or one just becomes completely dominated by the other and only a single image is visible. Is there an alternative for watermarks ? I found Watermarks.scala in the repository but could not make any sense out of it or use it.
@gwenzek and I have been working on new features for 1.5 but I want to be more ambitious and discuss 2.0. Please contribute to this thread with your ideas and API changes. This is just brainstorming at the moment, it doesn't mean we have to do it or will do it.
Hi,
Not an issue, but a question I couldn't find answer anywhere. Please, redirect me if there is a better place to ask this kind of question.
Do you have a raodmap published somewhere?
Do you plan to support comparing two images (like the image magick 'compare' function ( http://www.imagemagick.org/script/compare.php )?
Release 1.3.11
Hi,
I'm just getting starting tinkering with this and SBT, so maybe I'm doing something wrong, but i'm trying the AsyncImage directory example you gave and got this output:
.scala:6: not found: value AsyncImage
[error] dir.listFiles().foreach(file => AsyncImage(file).filter(GrayscaleFilter).onSuccess {
my test.scala file:
import com.sksamuel.scrimage._
object Test {
def main(args: Array[String]) = {
val dir = new java.io.File("/Downloads/ff_images")
dir.listFiles().foreach(file => AsyncImage(file).filter(GrayscaleFilter).onSuccess {
case image => image.writer(Format.PNG).withMaxCompression.write(file)
})
}
}
and my build.sbt
name := "img_srv"
version := "0.1"
scalaVersion := "2.11.0"
libraryDependencies += "com.sksamuel.scrimage" %% "scrimage-core" % "1.3.20"
libraryDependencies += "com.sksamuel.scrimage" %% "scrimage-filters" % "1.3.20"
Am I being a noob, or is there a problem here?
The Image.bound method currently does not accept scaleMethod as parameter, so I need to duplicate its functionality to call scaleTo with a different ScaleMethod. Do you think the method signature of bound should duplicate that of scaleTo?
Also, bound is not defined on the ImageLike interface and is not available in AsyncImage, can we add it there as well?
I also noticed that your recent merge of the change to the padTo/padWith broke ability to pass in a color into padTo. It needs the following fix (the color parameter passed on to padWith from padTo):
padWith(x, y, w - width - x, h - height - y, color)
Thanks!
P.S. I wanted to submit a pull request, but it seems the latest code in the repo doesn't compile, looks like you are in the middle of making some major changes there.
Hi,
I'm using upload in my website and I want to have differents formats of the image uploaded. So I do that:
Image(fileIO).cover(48, 48, ScaleMethod.FastScale).writer(com.sksamuel.scrimage.Format.PNG).withCompression(9).write(new File(path + "48/" + uuid + ".png"))
Image(fileIO).cover(128, 128, ScaleMethod.FastScale).writer(com.sksamuel.scrimage.Format.PNG).withCompression(9).write(new File(path + "128/" + uuid + ".png"))
Image(fileIO).cover(256, 256, ScaleMethod.FastScale).writer(com.sksamuel.scrimage.Format.PNG).withCompression(9).write(new File(path + "256/" + uuid + ".png"))
Image(fileIO).cover(512, 512, ScaleMethod.FastScale).writer(com.sksamuel.scrimage.Format.PNG).withCompression(9).write(new File(path + "512/" + uuid + ".png"))
During execution my RAM is around 900 at the beginning and then:
I feel I did something wrong, could you give me some advices?
Thank you
Whenever I am trying to resize and position a smaller image(png) onto a bigger one(jpg), the background of the smaller png image becomes completely white blocking the bigger image ? resizeTo. fit. scle to does all the same thing. How can I resize an image without interrupting the backgorund ? Is this a problem due to the image format ?
I'm trying to write my image out to an output buffer to be displayed at an endpt in Unfiltered. Trying any methods on the image instance raises the error below at present:
exception when typing img.write
class file needed by AsyncImage is missing.
reference type Future of package concurrent refers to nonexisting symbol. in file /Users/205250/projects/personalization-user-hub/src/main/scala/User.scala
scala.tools.nsc.symtab.Types$TypeError: class file needed by AsyncImage is missing.
reference type Future of package concurrent refers to nonexisting symbol.
Code below:
var img = Image(new File("pathtoimage.jpg"))
val out = new ByteArrayOutputStream()
img.write(out)
The emacs and eclipse scala editors expect this style by default: http://docs.scala-lang.org/style/
Eclipse, maybe also ensime, can auto-format code to this style.
You can also use Scalariform to format a whole project from the command line: https://github.com/mdr/scalariform
Please, add a watermark text example to the doc. It's another common manipulation on the images.
I don't know whether this is related to scrimage-core, or whether it is something else:
https://groups.google.com/d/topic/play-framework/Fy0PBqleoiI/discussion
How is it possible to position a watermark on an image ? resizeTo function resizes the canvas and takes in a position as well however, since resize fills the background with white even though I am manually setting the color to a transparent white during function call it does not work.
Hello,
I'm trying to install scrimage with sbt so I declared this in my file Build.scala
but it seems to install only a folder containing pom
files no jars
folder inside.
val appDependencies = Seq(
"com.sksamuel.scrimage" % "scrimage" % "1.3.3"
)
What should I do to have the jars?
Thanks for your help
As for now the method composite have been moved from Image to Canvas,
so should I move the AlphaComposite class to scrimage-canvas ?
To make the code compile and to be able to run some tests I re-added a lazy BufferedImage awt in the Image class.
It allows compilation but tests on filters and pixel access fail (because the awt is modified but not the raster)
Can I push this work around while we are working on removing totally awt ?
The tests allowed me to catch one more bug in Image.overlay and to test my rewrite of Image.flipX, Image.flipY.
Hi Stephen! I want to use scrimage in my project for warp and the other and can't realize how to do grid warp. I saw a warp in scrimage 0.7 but dont find it in the latest versions. Is it possible?
I modified the scaling benchmark to see how my translation to scala of the previous Bicubic scaling performed.
(ResampleOp -> ResampleOpScala)
The original result was a scala version 4x slower than the java one.
I replaced some "for" loops by "while", and moved declarations of var outside of loops.
It makes the code ugly but a bit faster.
Now it's typically 2x slower :
Testing Mortennobel Bicubic
Time: 59820 ms
Testing Mortennobel Bicubic in scala
Time: 130967 ms
But the numbers above change a lot at each run. Plus my computer has only 2 core so the parrallelization isn't so effective. Could someone try to reproduce those tests
and/or suggests me other improvements I can make ?
Its cropping without resizing first.
Fixed in 1.3.3
I have an image with the following attributes: PNG image data, 1440 x 2560, 8-bit/color RGB, non-interlaced. The image is attached.
I get this stack trace:
Caused by: java.lang.RuntimeException: Unparsable image
Nov 06 12:15:17 dg-admin-prod i-20aefec5: at com.sksamuel.scrimage.Image$$anonfun$apply$7.apply(Image.scala:790) ~[com.sksamuel.scrimage.scrimage-core_2.10-1.4.2.jar:1.4.2]
Nov 06 12:15:17 dg-admin-prod i-20aefec5: at com.sksamuel.scrimage.Image$$anonfun$apply$7.apply(Image.scala:790) ~[com.sksamuel.scrimage.scrimage-core_2.10-1.4.2.jar:1.4.2]
Nov 06 12:15:17 dg-admin-prod i-20aefec5: at scala.Option.getOrElse(Option.scala:120) [org.scala-lang.scala-library-2.10.4.jar:na]
Nov 06 12:15:17 dg-admin-prod i-20aefec5: at com.sksamuel.scrimage.Image$.apply(Image.scala:790) ~[com.sksamuel.scrimage.scrimage-core_2.10-1.4.2.jar:1.4.2]
Nov 06 12:15:17 dg-admin-prod i-20aefec5: at com.sksamuel.scrimage.Image$.apply(Image.scala:759) ~[com.sksamuel.scrimage.scrimage-core_2.10-1.4.2.jar:1.4.2]
When trying to run scrimage v1.4 on jdk1.6, I get the following error indicating that scrimage was compiled on jdk1.7.
The problem occurs for both Scala 2.10 and 2.11 versions. Since Scala 2.11 still targets jdk 6, I think your library should be compiled on jdk 6 as well even for Scala 2.11.
I have the following in build.sbt (this fails to run on jdk1.6):
libraryDependencies += "com.sksamuel.scrimage" %% "scrimage-core" % "1.4.1"
I am able to run scrimage v1.3.21 on jdk 1.6 using
libraryDependencies += "com.sksamuel.scrimage" %% "scrimage-core" % "1.3.21"
Thank you!
error java.lang.UnsupportedClassVersionError: thirdparty/mortennobel/ResampleFilter : Unsupported major.minor version 51.0
java.lang.UnsupportedClassVersionError: thirdparty/mortennobel/ResampleFilter : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at com.sksamuel.scrimage.Image$._copy(Image.scala:766)
at com.sksamuel.scrimage.Image$.apply(Image.scala:742)
at com.sksamuel.scrimage.Image$.apply(Image.scala:707)
at com.sksamuel.scrimage.Image$.apply(Image.scala:735)
java.lang.IllegalArgumentException: Numbers of source Raster bands and source color space components do not match
at java.awt.image.ColorConvertOp.filter(ColorConvertOp.java:482)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.acceptPixels(JPEGImageReader.java:1190)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImage(Native Method)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1158)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:966)
at javax.imageio.ImageIO.read(ImageIO.java:1448)
at javax.imageio.ImageIO.read(ImageIO.java:1352)
at com.sksamuel.scrimage.Image$.apply(Image.scala:483)
at com.sksamuel.scrimage.Image$.apply(Image.scala:478)
You've bumped the version, but I don't see the artifacts on Sonatype.
Hello!
Let's get the community going for this great lib! I have posted a question at stack overflow =)
Thank you in advance
Hello,
I want to do a small pull request, but I'm a little nervous to since the build is currently failing due to a bunch of unit tests not passing. You're probably well aware of this, but just in case, see here.
The fix wasn't immediately obvious to me, otherwise I would have just fixed it myself. I'm not sure what to do next. Should I submit my pull request anyway assuming that it doesn't make any additional tests fail? Wait for the tests to all pass first?
How does the === work for comparing images ? I am trying to write tests for my image processing functions and I am trying to find the most practical way to compare images.
This is really a luxury problem, but since at some point somebody will complain, let that somebody be me :-D
I noticed executing the code of issue #21 took suspiciously long. After some basic benchmarking it turns out it's when writing the PNG: it takes slightly above 3 seconds.
I am using this for benchmarking: https://github.com/Ichoran/thyme
This is the code I used to benchmark:
(using the jazz-musicians picture of #21)
val th = new Thyme
val pic = Image(new File("picture.jpg"))
println("With compression:")
th.pclock({
pic.writer(Format.PNG).withCompression(9).write(new File("picture_9.png"))
})
println("Without compression:")
th.pclock({
pic.writer(Format.PNG).write(new File("picture_0.png"))
})
Results:
For comparison I saved that same image (the jazz musicians) with Gimp as a PNG with max. compression (9) and I can safely say it took under a second.
My suspicion is that the PNG compressor does some operation which creates a lot of objects, or boxes/unboxes values, or something like that.
I'm using Image.cover to generate a 600x600 image from whatever image a user uploads, saving the result in S3 and then rendering the page using the resized image. If I upload a photo taken in portrait orientation on my iPhone, the resultant image after calling Image.cover(...) is rotated CCW by 90 degrees.
I seem to remember seeing issues like this on Windows, where the built-in image renderer doesn't respect the EXIF orientation data. Now I know png files don't contain EXIF data, however they can contain metadata such as orientation, and I suspect Apple must make use of this since the orientation is always correct on my Mac and iDevices.
I'm interested to hear if anyone else has had similar issues, and whether there is a well-known solution I could contribute back to this project.
We should add a way to detect the type of an arrayo of bytes, similar to this question on SO (just use that implementation with accreditation)
http://stackoverflow.com/questions/22534833/scala-detect-mimetype-of-an-arraybyte-image
Is it possible to write a PNG image with interlace/progressive?
Scrimage + filters v1.3.16:
Trying to load the attached image causes NoSuchElementException:
scala> import com.sksamuel.scrimage.Image
import com.sksamuel.scrimage.Image
scala> import java.io._
import java.io._
scala> Image(new File("d:\\tmp\\img.jpg"))
java.util.NoSuchElementException
at javax.imageio.spi.FilterIterator.next(ServiceRegistry.java:825)
at javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:528)
at javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:513)
at com.sksamuel.scrimage.Image$.apply(Image.scala:725)
at com.sksamuel.scrimage.Image$.apply(Image.scala:746)
at .<init>(<console>:20)
at .<clinit>(<console>)
at .<init>(<console>:7)
at .<clinit>(<console>)
at $print(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:734)
at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:983)
at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:573)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:604)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:568)
at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:756)
at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:801)
at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:713)
at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:577)
at scala.tools.nsc.interpreter.ILoop.innerLoop$1(ILoop.scala:584)
at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:587)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:878)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:833)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:833)
at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:135)
at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:833)
at scala.tools.nsc.interpreter.ILoop.main(ILoop.scala:900)
at org.jetbrains.plugins.scala.compiler.rt.ConsoleRunner.main(ConsoleRunner.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
scala>
Works great with other images, though.
I was wondering about the utility to have PixelType in Raster.
I hit a lot of problem to create Array of PixelType cause they don't have a ClassTag.
My reflection is that ultimately the data on the RAM is going to be an integer,
so while we can let the Raster choose how it stores colors (RGB, ARGB, grey level, ...), we may force it to use Int as intermediary data type.
It's not so elegant but I don't think the raster is the best place for elegance, and it would ensure us that java arrays will be used in the background.
I am trying create a function named: def border(color: Color, size: Int): ImageProcessor. Image processor is an object which processes images and the border method basically calls pad function within scrimage library. I have tried many different ways to create a border with color but event though the size changes I could not change the color. I have tried to use scrimage colors or java.awt colors. I have tried it with an Image object as well as with a FileInputStream Object.
val x = new FileInputStream(file)
val y: Image = Image(x).pad(size,color)
This is one of the ways I have tried or a simpler version is as follows
val newImage = Image(file).pad(size, color)
Both of them do not give correct results.
Hello dear Stephen,
at the first of all I would like to thank you very much for writing such a good tool! I like the library, it's speed (especially for the best quality) and also I like it is native scala library. And the thing I like most of all is the API, I really like it!
I noticed a weird behaviour of library (I'm not sure it is library, but it is what i'm thinking now): sometimes it convers images very good and correctly. But sometimes I see that image has something like color mixed in it. And sometimes I even see something like rainbow instead of image. So, just colored curves, but not the image. This is a tomcat(and jetty) application. After I have restarted tomcat, images are converted correctly (or with different errors, so, behaviour will be changed). The same situation is under jetty.
Unfortunately, I was not able to create reproducing steps for you, sorry. But I have attached images with "mixed in" red color. And their originals too.
Images were converted with next code:
im = scrimage.Image(image.data.is).fit(dim.width.is, dim.height.is)
data(im.write(scrimage.Format.JPEG)) //saving image to database
Please, see examples of images below.
Please, let me know if I can help more.
Thanks,
Andrey.
In the AsyncImage all the operations return a Future[T], but I cannot specify my own ExecutionContext. It is imported by the library code.
It can be easily fixed by requiring an implicit ExecutionContext on AsyncImage creation instead.
Libraries should never choose the threadpool/context on which operations will run.
If you update this, it will be a minor change, especially because the ExecutionContext has a nice error message when it can't be found.
I often find myself trying to remember which operation does what.
bound
takes an image and resizes it up to the given dimensions. If its bigger then it shrinks it, if its smaller then it enlarges it. But it maintains aspect ratio.
Maybe max
is a better word for this, or scaleWithAspect
. I often get confused between bound and constrain.
Hi there,
I'm trying to use your library in a Play 2.2
project on Scala version 2.10.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_51)
, however I get the following error whenever I call the .write()
method to save the manipulated image:
[RuntimeException: java.lang.UnsupportedClassVersionError: thirdparty/pngtastic/PngImage]
The code I'm using is quite straight forward:
var is = new java.io.BufferedInputStream(new java.io.FileInputStream(picture.ref.file)) // picture.ref.file is the image file being submitted via a POST MultiPartForm in Play.
var file = org.apache.commons.io.IOUtils.toByteArray(is)
val img = Image(file)
img.write(new File(s"image.png"))
Full stack trace below:
play.api.Application$$anon$1: Execution exception[[RuntimeException: java.lang.UnsupportedClassVersionError: thirdparty/pngtastic/PngImage]]
at play.api.Application$class.handleError(Application.scala:293) ~[play_2.10.jar:2.2.0]
at play.api.DefaultApplication.handleError(Application.scala:399) [play_2.10.jar:2.2.0]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$2$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:261) [play_2.10.jar:2.2.0]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$2$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:261) [play_2.10.jar:2.2.0]
at scala.Option.map(Option.scala:145) [scala-library.jar:na]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$2.applyOrElse(PlayDefaultUpstreamHandler.scala:261) [play_2.10.jar:2.2.0]
Caused by: java.lang.RuntimeException: java.lang.UnsupportedClassVersionError: thirdparty/pngtastic/PngImage
at play.api.mvc.ActionBuilder$$anon$1.apply(Action.scala:314) ~[play_2.10.jar:2.2.0]
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4$$anonfun$apply$5.apply(Action.scala:109) ~[play_2.10.jar:2.2.0]
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4$$anonfun$apply$5.apply(Action.scala:109) ~[play_2.10.jar:2.2.0]
at play.utils.Threads$.withContextClassLoader(Threads.scala:18) ~[play_2.10.jar:2.2.0]
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4.apply(Action.scala:108) ~[play_2.10.jar:2.2.0]
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4.apply(Action.scala:107) ~[play_2.10.jar:2.2.0]
Caused by: java.lang.UnsupportedClassVersionError: thirdparty/pngtastic/PngImage
at com.sksamuel.scrimage.io.PngWriter.write(PngWriter.scala:37) ~[scrimage-core_2.10-1.3.5.jar:1.3.5]
at com.sksamuel.scrimage.ImageLike$class.write(ImageLike.scala:230) ~[scrimage-core_2.10-1.3.5.jar:1.3.5]
at com.sksamuel.scrimage.Image.write(Image.scala:38) ~[scrimage-core_2.10-1.3.5.jar:1.3.5]
at com.sksamuel.scrimage.ImageLike$class.write(ImageLike.scala:223) ~[scrimage-core_2.10-1.3.5.jar:1.3.5]
at com.sksamuel.scrimage.Image.write(Image.scala:38) ~[scrimage-core_2.10-1.3.5.jar:1.3.5]
at com.sksamuel.scrimage.ImageLike$class.write(ImageLike.scala:219) ~[scrimage-core_2.10-1.3.5.jar:1.3.5]
Assistance appreciated!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.