Open wangjinbei opened 7 years ago
With what version did you test this? I rewrote the image watermarking, and can look into this.
const Version = "1.0.7"
Can you give this version a try?
It's not work~~ After : "go get -u github.com/h2non/bimg"
You probably used master?
import "github.com/h2non/bimg"
Because
import gopkg.in/h2non/bimg.v1
doesn't support image watermarkingyes! bimg.v1 doesn't support image watermarking
package main
import (
"fmt"
"os"
"github.com/h2non/bimg"
)
func main() {
buffer, err := bimg.Read("/Users/william/gocode/src/awesomeProject/imagek/1.jpeg")
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
bufferWater, err := bimg.Read("/Users/william/gocode/src/awesomeProject/imagek/1.png")
watermark := bimg.WatermarkImage{
Left: 0,
Top: 0,
Buf: bufferWater,
Opacity: 0.25,
}
newImage, err := bimg.NewImage(buffer).WatermarkImage(watermark)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
bimg.Write("new.jpg", newImage)
}
So to try the PR change your import to github.com/waldophotos/bimg
(go get github.com/waldophotos/bimg
)
can not work...
package main
import (
"fmt"
"os"
"github.com/waldophotos/bimg"
)
func main() {
buffer, err := bimg.Read("1.jpeg")
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
bufferWater, err := bimg.Read("1.png")
watermark := bimg.WatermarkImage{
Left:0,
Top:0,
Buf:bufferWater,
Opacity: 1,
}
newImage, err := bimg.NewImage(buffer).WatermarkImage(watermark)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
bimg.Write("new.jpg", newImage)
}
Can you be more specific, and maybe supply the images your testing with?
Original image is like this :
After watermarking :
And Images info are different as follows:
Test file:
Only see PNG images, not the original JPG?
Can you access this image link?
Or you can use this github link
Yeah, got it... Even not doing watermarking is changing the colour profile, not sure what is happening. Will look into it.
👌 But,If do not add watermark, the color will not change .
The problem is a little bit of color change,will solve this problem?
Could be the watermarking. Will look into it. Thanks for all the info!
Okay, I wrote the following code:
package main
import (
"fmt"
"os"
"github.com/waldophotos/bimg"
)
func main() {
buffer, err := bimg.Read("1.jpeg")
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
bufferWater, err := bimg.Read("1.png")
watermark := bimg.WatermarkImage{
Left: 0,
Top: 0,
Buf: bufferWater,
Opacity: 1,
}
original := bimg.NewImage(buffer)
s, err := bimg.Size(buffer)
height := s.Height
withWatermark, err := original.WatermarkImage(watermark)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
bimg.Write("new.jpg", withWatermark)
size := 400
originalCropSouth, _ := original.Extract(height-size, 0, size, size)
options := bimg.Options{
Top: -1,
Left: 0,
AreaWidth: size,
AreaHeight: size,
Type: bimg.JPEG,
}
originalCropNorth, _ := bimg.NewImage(bufferWater).Process(options)
withWatermarkCropSouth, _ := bimg.NewImage(withWatermark).Extract(height-size, 0, size, size)
withWatermarkCropNorth, _ := bimg.NewImage(withWatermark).Process(options)
bimg.Write("new.jpg", withWatermark)
bimg.Write("crop_watermark.jpg", originalCropNorth)
bimg.Write("crop_with_watermark.jpg", withWatermarkCropNorth)
bimg.Write("crop_photo.jpg", originalCropSouth)
bimg.Write("crop_photo_with_watermark.jpg", withWatermarkCropSouth)
}
This piece, adds a watermark image to the original image and when done, it extracts a portion of the original image and of the watermarked image. Because the watermark image is PNG, I also convert the PNG to JPG when extract a piece of it, to get a similar result.
When doing this, I don't see any color change. I added the resulting images.
Photo
Photo with watermark
Watermark
Photo with watermark
I'm not seeing any color changes. Env:
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/ajdevries/gocode"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.8.1/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.8.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/84/hpd_s5nj4l9394fnzr4z2ksh0000gn/T/go-build706600612=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
vips-8.4.5-Fri Mar 31 09:06:59 CEST 2017
Can you extract a portion of the original image and of the watermarked image here?
The difference is as follows Original image:
After watermarking:
I see the difference and will do some more testing. A guess, could it be related to the image format? When creating an watermarker images with a PNG and a JPG file -where the PNG is the watermark - results in a JPG file. Which uses a different compressing (lossy) instead of PNG (lossless compression).
A test could be watermarking a PNG image instead of a JPG.
Hi @ajdevries, sorry for the late reply. Unfortunately,i can only use this JPG image to reproduce the problem(I can notice the problem clearly). If watermarking images with a PNG and a JPG file, the color will change slightly, is this a problem?
So converting an image from PNG to JPG can cause quality loss and maybe color changes. I don't think that this is related to watermarking.
You can save the JPG image as a PNG image (in a Photo Editor) and try the watermark functionality with two PNG files.
go env:
go version go1.6.3 linux/amd64 GOARCH="amd64" GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/usr/local/src/gocode" GORACE="" GOROOT="/usr/lib/golang" GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64" GO15VENDOREXPERIMENT="1" CC="gcc" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0" CXX="g++" CGO_ENABLED="1"
Code:
Result: new.jpg missing "Color Profile: Display P3" , And there is a slight change in color
1.jpeg info:
new.jpg info: