Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Sep 20 11:59
    sksamuel commented #233
  • Sep 20 11:56
    grewaviv commented #233
  • Sep 20 11:48
    sksamuel commented #233
  • Sep 20 11:47
    grewaviv commented #233
  • Sep 20 11:44
    sksamuel commented #233
  • Sep 20 05:39
    grewaviv opened #233
  • Jul 29 18:46
    sksamuel closed #232
  • Jul 29 18:40
    binbash5447 opened #232
  • Jul 12 02:03
    sksamuel closed #231
  • Jul 12 02:03
    sksamuel commented #231
  • Jul 09 12:11
    an-tex opened #231
  • Jun 06 18:45
    sksamuel closed #230
  • Jun 06 18:45
    sksamuel commented #230
  • Jun 04 18:56
    sksamuel opened #230
  • May 28 20:46
    sksamuel commented #229
  • May 28 16:12
    MaxGierlachowski closed #229
  • May 28 16:12
    MaxGierlachowski commented #229
  • May 28 15:50
    sksamuel commented #229
  • May 28 15:46
    MaxGierlachowski opened #229
  • May 26 23:20
    ToxicMushroom closed #228
Ashesh Ambasta
@asheshambasta
We end up with an image like this from an image that is like this
Sam Sam
@sksamuel
I've seen similar myself and never tracked down what it is
Bill Frasure
@swoogles
I've got a pretty simple question- can I get an example of drawing text on a scrimage.Image instance? I've got no problem applying filters and other operations, but I'm not seeing how to handle text
It looks like you've got to convert things to an awt.Graphics2D instance, but I'd prefer to just work with the Image instance if possible
Bill Frasure
@swoogles
Some context:
import com.sksamuel.scrimage.Image
import com.sksamuel.scrimage.filter.SnowFilter
import com.sksamuel.scrimage.nio.JpegWriter
import com.sksamuel.scrimage.Color
import com.sksamuel.scrimage.canvas.DrawableString
import com.sksamuel.scrimage.canvas.Drawable
import import ammonite.ops.Path

import javax.imageio.ImageIO
import java.awt.Graphics

// Needed for SnowFilter for some weird reason.
import scala.concurrent.ExecutionContext.Implicits.global

val rippleAmplitude = 30f
val rippleWaveLength = 50f

val photoMessage = "Happy Holidays!"

def addTextWithScrimage(image: Image) = {
  val text: DrawableString = Drawable.apply("text for image", 100, 50)
  text.draw(image)
}

// Currently using this. Requires another round trip to disk, and additional dependencies in this file.
def addTextWithImageIO(imgPath: Path, text: String) = {
  val graphicsImg = ImageIO.read(imgPath.toIO)
    val height = graphicsImg.getHeight
    val width = graphicsImg.getWidth
    val g = graphicsImg.getGraphics();
  g.setFont(g.getFont().deriveFont(200f));
  g.drawString(text, 100, height - 100);
  g.dispose();
  ImageIO.write(graphicsImg, "jpg", imgPath.toIO);
}

for (imgPath <- copyFreshImages(originalImgDir, manipulatedImgDir);
    img = Image.fromFile(imgPath.toIO)
    .filter( SnowFilter())
    .fit(1600, 1200, Color.Black)
    .pad(300, Color.Black)
    .output(imgPath.toIO)(JpegWriter())
  ) yield { 
  addTextWithImageIO(imgPath, photoMessage) // Side effecting operation.  Would reallly like it to create new versions of the img in memory in the same way as the other operations.
  img 
}
Sam Sam
@sksamuel
If you use the 3.0 snapshot, you just create a canvas
and then you can wrap onto that, a canvas is basically a wrapper around an image which accepts "Drawables"
import com.sksamuel.scrimage.canvas.Canvas._
image. draw(DrawableString(k.toString, x + 6, y + 26, { g2 => g2.setBlack() g2.setAntiAlias(true) g2.setFont(new Font("Helvetica", Font.BOLD, 26)) }))
You need to pass in a function : Graphics2D -> Unit, which configures the G2
@swoogles
Bill Frasure
@swoogles

What's the best way of getting my hands on the 3.0.0 snapshot?
I checked out the project, built the 3 jars (core, filters, io-extra) by running "package" in each project, and put them in:

$HOME/.ivy2/local/com.sksamuel.scrimage/scrimage-core_2.11/3.0.0-SNAPSHOT/jars/scrimage-core_2.11-3.0.0-SNAPSHOT.jar
$HOME/.ivy2/local/com.sksamuel.scrimage/scrimage-filters_2.11/3.0.0-SNAPSHOT/jars/scrimage-filters_2.11-3.0.0-SNAPSHOT.jar
$HOME/.ivy2/local/com.sksamuel.scrimage/scrimage-io-extra_2.11/3.0.0-SNAPSHOT/jars/scrimage-io-extra_2.11-3.0.0-SNAPSHOT.jar

but I'm unable to access anything in com.sksamuel after I load them into this Jupyter notebook via:

classpath.add("com.sksamuel.scrimage" %% "scrimage-core" % "3.0.0-SNAPSHOT")                                                                                                                                                                           
classpath.add("com.sksamuel.scrimage" %% "scrimage-io-extra" % "3.0.0-SNAPSHOT")                                                                                                                                                                       
classpath.add("com.sksamuel.scrimage" %% "scrimage-filters" % "3.0.0-SNAPSHOT")
Bill Frasure
@swoogles
If they are available somewhere that I can pull in without this manual building, that'd be great
Bill Frasure
@swoogles
Another note - You use DrawableString in your example, but the source shows that's Deprecated in favor of Text for version 3.0.0
Sam Sam
@sksamuel
Yes, use Text
@swoogles the snapshots are on maven snapshot central so you will need to add it to your build as a repo
Bill Frasure
@swoogles
Great, thanks. It'll be a little bit before I can get back to this, but I think I'll be all set after that. I got it working with 2.1.7, so I'll switch to the non-deprecated versions once I've got 3.0.0
Sam Sam
@sksamuel
Ok
Mohamed Abou Messaad
@medabme
Hi, I'm trying to use scrimage library in my project to process some images (application of filters), as a beginner with scala I found several problems. Can anyone help me to add the library to my project and use scrimage-filters to process some images??
Mohamed Abou Messaad
@medabme

this is my code

package com.sksamuel.scrimage.filter
import com.sksamuel.scrimage.Image
import com.sksamuel.scrimage.nio.JpegWriter
import javax.imageio.ImageIO
import java.io.File
import com.sksamuel.scrimage.nio.PngWriter

object Test extends App {
  implicit val writer: PngWriter = PngWriter.MaxCompression

  //val path = Paths.get("/test-orig.jpg")
  val inFile = Image.fromFile(new File("/gta.jpg"))
  //val outFile = ImageIO.write(outFile, "jpg", new File("/gta_Blur"))
  val outFile = Image.fromFile(inFile).filter(BlurFilter).flipX.output(outFile)(JpegWriter()) // specified Jpeg
}

errors:

[error] /home/med/workspace/IdeaProjects/img-filter/src/main/scala/Test.scala:22:32: type mismatch;
[error]  found   : com.sksamuel.scrimage.Image
[error]  required: java.io.File
[error]   val outFile = Image.fromFile(inFile).filter(BlurFilter).flipX.output(outFile)(JpegWriter()) // specified Jpeg
[error]                                ^
[error] one error found

any help please?

Laurent Valdes
@valdo404
hi guys, any chance to have a published version on any repository ?
Sergey Torgashov
@satorg

Hey @sksamuel and everyone!

I'm trying to start working with ScrImage 4.0.6. What I'd like to achieve is to load an image from some format (jpeg or png), do some transformations on it and save the result image in the same format the original image was loaded from.

Do I understand correctly, that to understand the source image format, I always have to call FormatDetector.detect(...) separately from image loading? I.e. there's no way to understand the source format from the loaded ImmutableImage, isn't there?

Sam Sam
@sksamuel
You can do it directly from ImageLoader.
It will detect the type and return an ImmutableImage
Sergey Torgashov
@satorg
@sksamuel but how do I know a format of a particular image after it gets loaded with ImageLoader?
1 reply
lekan
@horlahlekhon
Hi everyone, is there a way to write a .tiff file as the output of an operation. i want to pass in a jpeg and after editing, i want it to be a .tiff. is this possible. thanks
6 replies
lekan
@horlahlekhon

Hi everyone, how does one mix the versions together, the depenndencies seems to not be compatible with each other. like i want

* format extra
* scrimage core
* scrimage filters

but i can't get the same version for the 3.
if i use core and filters < 2 .x format-extra doesnt seem to have less than 2.x version .

and if i decide to use the same version for the three i get

com.sksamuel.scrimage#scrimage-core_2.12;4.0.8: not found
com.sksamuel.scrimage#scrimage-filters_2.12;4.0.8: not found

how does one mix these three dependecies together ?

8 replies
Anton Kuroedov
@atk91
Hey everyone! How to adjust image saturation? There's no something like "saturation" or "modulate" in available operations.
Anton Kuroedov
@atk91
Also, it seems like opacity filter is actually doing transparency, since on amount of 1.0f image becomes fully transparent, and on 0.0f it is (almost) unchanged
import com.sksamuel.scrimage.ImmutableImage                                                                                                                                                                                                    
import com.sksamuel.scrimage.nio.PngWriter                                                                                                                                                                                                     
import com.sksamuel.scrimage.filter.OpacityFilter                                                                                                                                                                                              

object Main extends App {                                                                                                                                                                                                                      
  val in = new java.io.File("./img.png")                                                                                                                                                                                                       
  val out = new java.io.File("./out.png")                                                                                                                                                                                                      
  ImmutableImage.loader().fromFile(in).filter(new OpacityFilter(0.80f)).output(new PngWriter(), out)                                                                                                                                           
}
A code snippet to play with
Anton Kuroedov
@atk91
@sksamuel When trying to adjust saturation by converting image pixels to hsv, adjusting s, and then converting back, I discovered a strange behaviour which I believe is a bug, so I opened an issue sksamuel/scrimage#216
Sam Sam
@sksamuel
Thanks for the bug report, I pushed a fix out over the weekend
Gerry Fletcher
@gerryfletch
Heya, where abouts can I find release notes? I upgraded from 4.0.4 to 4.0.11 and have some functionality that has changed with respect to scaling the size of images
I was reducing the size of a 1000x1000 image to 400x400, and for some reason the file size has roughly doubled rather than roughly halving
1 reply
Gerry Fletcher
@gerryfletch
Tested 4.0.[4/5/6/7/8/9]. It first fails on 4.0.10
Looks like the tags 10/11 have been removed from GitHub, is that related? 4.0.12 (latest) does not work either
Sam Sam
@sksamuel
Let me check the changes
Sam Sam
@sksamuel
It must be this: sksamuel/scrimage@dbe0c35
Gerry Fletcher
@gerryfletch
Hm, I'm not sure what the implications of those changes are
Sam Sam
@sksamuel
@gerryfletch I've fixed this regression and released 4.0.13. I've also added another scale mode, ProgressiveBilinear which is almost as good but 33% faster. See what you think.
Benchmarks here: https://github.com/sksamuel/scrimage/runs/1769005309?check_suite_focus=true#step:3:196
Gerry Fletcher
@gerryfletch
That's awesome! Thank you so much for the library, it's a real life saver
Gerry Fletcher
@gerryfletch
Hm I've just tried both 4.0.14 and 4.0.15 and the same issue
Ah, let me make sure it's not caching those dependencies from the last time...
Gerry Fletcher
@gerryfletch
Okay, perhaps I need to revisit my usage of the library. I generate a thumbnail (100x100), a 'display' at (400x400), and a 'gallery' at (2400x2400). Thumbnail and display are styled cover, but the gallery is bound, so it just uses 2400 as the maximums not forced height/width. Looking at the API, I think scaleTo will stretch the image if the bounds are not already known + calculated?
Sam Sam
@sksamuel
scaleTo will scale to exactly the dimensions you give, so a 200x200 image could be scaled to 20 x 100000 if you wanted using scaleTo
each of the scaleX methods, cover, fit, bound, max and so on all accept a scale method to determine quality
The micro site has descriptions and examples for each of the operations, for example here is cover: https://sksamuel.github.io/scrimage/cover/
LeComptoirDesPharmacies
@LeComptoirDesPharmacies
Hi @sksamuel,
We are searching for a library which is able to resize animated GIF (and keep the animation) in Java.
We found your library 'scrimage' which seems really good. Do you know if it have this capability ?
Yours faithfully,
LCDP
1 reply
Sergey Torgashov
@satorg
Hi there. I'm struggling to understand, what was the reasoning behind deriving ImmutableImage from MutableImage? I'm wondering because it looks like even if we got an ImmutableImage instance we're still able to mutate it "in-place" just because it inherits all these methods from MutableImage ? In other words, ImmutableImage is not an immutable actually, but rather it just provides additional methods with copy-on-write semantic.