Closed c23-cbu closed 2 years ago
Well, you're orphaning the watermark operation node and going back to the original decoded image to encode. If you did decode = decode.Watermark(...) to keep track of that operation before you encode it, it would work.
On Wed, Jan 12, 2022, 4:20 AM c23-cbu @.***> wrote:
Hello, first of all, congrats for this wrapper :) not sure if it's an issue or my implementation but, when I set the result of decode function in a variable, I got only the basic image without watermark.
NOT Working :
// Get File Stream var fileStream = File.OpenRead(filePath); var fileBytes = new byte[fileStream.Length]; fileStream.Read(fileBytes, 0, fileBytes.Length); fileStream.Close(); // Get Watermark Stream var watermarkStream = File.OpenRead(watermarkPath); var watermarkBytes = new byte[watermarkStream.Length]; watermarkStream.Read(watermarkBytes, 0, watermarkBytes.Length); watermarkStream.Close(); using var job = new ImageJob(); var decode = job.Decode(fileBytes); decode.Watermark(new BytesSource(watermarkBytes), new WatermarkOptions() .SetMarginsLayout( new WatermarkMargins(WatermarkAlign.Image, 1, 1, 1, 1), WatermarkConstraintMode.Within, new ConstraintGravity(90, 90)) .SetOpacity(0.5f) .SetHints(new ResampleHints().SetSharpen(15f, SharpenWhen.Always)) .SetMinCanvasSize(1, 1)); var result = await decode.EncodeToBytes(new MozJpegEncoder(80, true)) .Finish().InProcessAsync(); return result.First.TryGetBytes().Value.ToArray();
Working :
// Get File Stream var fileStream = File.OpenRead(filePath); var fileBytes = new byte[fileStream.Length]; fileStream.Read(fileBytes, 0, fileBytes.Length); fileStream.Close(); // Get Watermark Stream var watermarkStream = File.OpenRead(watermarkPath); var watermarkBytes = new byte[watermarkStream.Length]; watermarkStream.Read(watermarkBytes, 0, watermarkBytes.Length); watermarkStream.Close(); using var job = new ImageJob(); var decode = await job.Decode(fileBytes) .Watermark(new BytesSource(watermarkBytes), new WatermarkOptions() .SetMarginsLayout( new WatermarkMargins(WatermarkAlign.Image, 1, 1, 1, 1), WatermarkConstraintMode.Within, new ConstraintGravity(90, 90)) .SetOpacity(0.5f) .SetHints(new ResampleHints().SetSharpen(15f, SharpenWhen.Always)) .SetMinCanvasSize(1, 1)) .EncodeToBytes(new MozJpegEncoder(80, true)) .Finish().InProcessAsync(); return decode.First.TryGetBytes().Value.ToArray();
Any idea what is going wrong ? Thanks
— Reply to this email directly, view it on GitHub https://github.com/imazen/imageflow-dotnet/issues/40, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2LH4ZPC6EZFR3I3YXNY3UVVPXBANCNFSM5LYWVAFQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you are subscribed to this thread.Message ID: @.***>
Exact, it works like a charm. Thanks a lot @lilith
Hello, first of all, congrats for this wrapper :) not sure if it's an issue or my implementation but, when I set the result of decode function in a variable, I got only the basic image without watermark.
NOT Working:
Working:
Any idea what is going wrong ? Thanks
edit: highlighting code