Comments (14)
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")
}
from scrimage.
So here is my outup
Main image:
from scrimage.
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.
With the code I put above with an alpha value of 1 (new AddComposite(1.0)), I go this:
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.
This one is good enough and these are just example images. However, my results are completely different:
from scrimage.
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.
currentImage = currentImage.composite(new AddComposite(1.0), watermarkImage)
This is how I use it and I defined AddComposite same as here.
from scrimage.
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.
A resizing operation is applied before the composite function is called but that should not matter
from scrimage.
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.
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")
from scrimage.
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.
In resizeTo i was able to indicate a Position for the image, how can I do the same thing by using scaleTo ?
from scrimage.
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)
- Using the MultiplyComposite causes "dstIn must store pixels as INT but was 0" HOT 2
- Is it support for Spark 3? HOT 2
- JpegWriter.NoCompression preset is misleading HOT 1
- Animated GIF not Compressed HOT 5
- WebP - embedded Versions HOT 3
- Some Webp fail to parse HOT 6
- Unable to use composite on images HOT 1
- WebP & ImageOutputStream HOT 2
- on amazon linux ,error occur HOT 5
- WebP parsing is broken on latest version HOT 2
- Feature Request: Scala 3 support HOT 2
- PNG image compression ineffective HOT 1
- Some filters don't work for non ARGB images HOT 4
- StreamingGifWriter#withInfiniteLoop method doesn't work correctly HOT 3
- How to write text on image
- ARM (M1/M2) support for WEBP HOT 14
- average implementation is not correct HOT 2
- Security vulnerability in the webp library. HOT 1
- Typo in microsite HOT 1
- Unable to Read JPEG Files HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scrimage.