Giter Club home page Giter Club logo

Comments (14)

gwenzek avatar gwenzek commented on May 17, 2024

Here is a sample of code for watermarking. I don't know why there is no 'Add' composite in scrimage, but you can add it easily:

import com.sksamuel.scrimage.Image
import com.sksamuel.scrimage.composite._
import thirdparty.romainguy.BlendComposite.BlendingMode
import thirdparty.romainguy.BlendComposite

object Main extends App {
  class AddComposite(alpha: Double) extends BlenderComposite(BlendComposite.BlendingMode.ADD, alpha.toFloat)

  val bird = Image(new java.io.File("bird_small.png"))
  val watermark = Image(new java.io.File("watermark.png"))

  val marked = bird.composite(new AddComposite(0.5), watermark)

  marked.write("bird_marked.png")
}

bird_small.png
bird_small

watermark.png
watermark

bird_marked.png
bird_marked

from scrimage.

igalbenardete avatar igalbenardete commented on May 17, 2024

So here is my outup
Main image:
color

Watermark:
special_5

RESULT:
car

from scrimage.

igalbenardete avatar igalbenardete commented on May 17, 2024

By the way main image is jpeg and the watermark is png. Just letting you know so that that is not the problem, hopefully.

from scrimage.

gwenzek avatar gwenzek commented on May 17, 2024

With the code I put above with an alpha value of 1 (new AddComposite(1.0)), I go this:
car_sold

Which seems better (the car isn't altered). But if you are looking for a watermarking that can be use for a lot of images I wouldn't choose something with red in it.

from scrimage.

igalbenardete avatar igalbenardete commented on May 17, 2024

This one is good enough and these are just example images. However, my results are completely different:
x

from scrimage.

gwenzek avatar gwenzek commented on May 17, 2024

I wasn't able to reproduce your result, but here is how I got mine:

import com.sksamuel.scrimage.Image
import com.sksamuel.scrimage.composite._
import thirdparty.romainguy.BlendComposite.BlendingMode
import thirdparty.romainguy.BlendComposite

object Main extends App {
  class AddComposite(alpha: Double) extends BlenderComposite(BlendComposite.BlendingMode.ADD, alpha.toFloat)

  val car = Image(new java.io.File("car.jpg"))
  val sold = Image(new java.io.File("sold.png"))

  val car_sold = car.composite(new AddComposite(1), sold)
  car_sold.write("car_sold.png")
}

Which composite and alpha parameter did you choose ?

from scrimage.

igalbenardete avatar igalbenardete commented on May 17, 2024
currentImage = currentImage.composite(new AddComposite(1.0), watermarkImage)

This is how I use it and I defined AddComposite same as here.

from scrimage.

gwenzek avatar gwenzek commented on May 17, 2024

Really weird ...

Is their any other operation that you apply to your currentImage before or after that ?
because the result is bigger (800x600) than the car image (628x417) but it should be of the same size.

Indeed img.composite(..., other) is always of the size of img

from scrimage.

igalbenardete avatar igalbenardete commented on May 17, 2024

A resizing operation is applied before the composite function is called but that should not matter

from scrimage.

igalbenardete avatar igalbenardete commented on May 17, 2024

I fixed it. The watermark image is resized as well. When the resize function returns an image, it covers the background with white background. However the watermark png has a transparent background. Is there a way to avoid having a white background while using resize function ? Additionally, does the watermark image has to be transparent ? What if I want to make it completely opaque ? (This means that I just want to put one image on top of the other)

from scrimage.

gwenzek avatar gwenzek commented on May 17, 2024

ok this is interesting.
I tested it and scale doesn't remove transparency. But there are operations that does remove it, like saving as JPEG and load back (JPEG doesn't handle transparency)

In my first example, I didn't use a transparent image, but an image with a black background, because it is 'transparent' respectively to the add composite.

If you just want to draw over, just use the overlay method: car.overlay(sold).write("car_sold_2.png")
car_sold_2

from scrimage.

igalbenardete avatar igalbenardete commented on May 17, 2024

Ok perfect this looks like it is working. So the only difference between scaleTo and resize is basically the background handling ?
With the composite and using resize with a color with 0 alpha still does not make it work but I guess scaleTo will be just fine for now. Overlay was what I am looking for thank you very much.

from scrimage.

igalbenardete avatar igalbenardete commented on May 17, 2024

In resizeTo i was able to indicate a Position for the image, how can I do the same thing by using scaleTo ?

from scrimage.

gwenzek avatar gwenzek commented on May 17, 2024

The readme provides a bit of information about this. resize doesn't scale your image so if you resize to a bigger image it will have to fill the background with the provided color (white by default).

overlay(overlayImage: Image, x: Int = 0, y: Int = 0): Image let you specify where you want to draw the overlayImage. I think that would be the way to go.

from scrimage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.