imazen / imageflow-dotnet-server

A super-fast image server to speed up your site - deploy as a microservice, serverless, or embeddable.
https://docs.imageflow.io
GNU Affero General Public License v3.0
252 stars 33 forks source link

Watermark resource not found? #22

Closed JayVDZ closed 4 years ago

JayVDZ commented 4 years ago

I'm trying to add a watermark and have used the example code but am getting the following error:

The specified resource does not exist.
Cannot locate watermark "" at virtual path "/img/londonbikers-logo-trans.png"

The file can be requested at that URL so I'm a bit confused. Any ideas what I'm doing wrong? My ASP.NET Core configuration is:

services.AddImageflowAzureBlobService(new AzureBlobServiceOptions(Configuration["Storage:ConnectionString"], new BlobClientOptions()).MapPrefix("/i/", Constants.StorageOriginalContainerName));

services.AddImageflowDiskCache(new DiskCacheOptions(Configuration["ImageFlow:DiskCachePath"]));

and

app.UseImageflow(new ImageflowMiddlewareOptions()
                .SetJobSecurityOptions(new SecurityOptions()
                    .SetMaxDecodeSize(new FrameSizeLimit(10000, 10000, 60))
                    .SetMaxFrameSize(new FrameSizeLimit(10000, 10000, 60))
                    .SetMaxEncodeSize(new FrameSizeLimit(10000, 10000, 30)))
                .SetAllowDiskCaching(true)
                .AddCommandDefault("down.filter", "mitchell")
                .AddWatermark(
                    new NamedWatermark("lb-corner-logo", "/img/londonbikers-logo-trans.png",
                        new WatermarkOptions()
                            .SetFitBoxLayout(new WatermarkFitBox(WatermarkAlign.Image, 10, 10, 90, 90), WatermarkConstraintMode.Within, new ConstraintGravity(100, 100))
                            .SetOpacity(0.7f)
                            .SetHints(new ResampleHints()
                                .SetResampleFilters(InterpolationFilter.Robidoux_Sharp, null)
                                .SetSharpen(7, SharpenWhen.Downscaling))
                            .SetMinCanvasSize(800, 600))).AddWatermarkingHandler("/i", args => {
                                if (args.Query.TryGetValue("water", out var value) && value == "mark")
                                {
                                    args.AppliedWatermarks.Add(new NamedWatermark(null, "/img/londonbikers-logo-trans.png", new WatermarkOptions()));
                                }
                }));
lilith commented 4 years ago

You need to call MapPath on ImageflowMiddlewareOptions for / to mount it most likely.

On Sat, Aug 29, 2020, 3:32 AM Jay Van der Zant notifications@github.com wrote:

I'm trying to add a watermark and have used the example code but am getting the following error:

The specified resource does not exist. Cannot locate watermark "" at virtual path "/img/londonbikers-logo-trans.png"

The file can be requested at that URL so I'm a bit confused. Any ideas what I'm doing wrong? My ASP.NET Core configuration is:

services.AddImageflowAzureBlobService(new AzureBlobServiceOptions(Configuration["Storage:ConnectionString"], new BlobClientOptions()).MapPrefix("/i/", Constants.StorageOriginalContainerName));

services.AddImageflowDiskCache(new DiskCacheOptions(Configuration["ImageFlow:DiskCachePath"]));

and

app.UseImageflow(new ImageflowMiddlewareOptions() .SetJobSecurityOptions(new SecurityOptions() .SetMaxDecodeSize(new FrameSizeLimit(10000, 10000, 60)) .SetMaxFrameSize(new FrameSizeLimit(10000, 10000, 60)) .SetMaxEncodeSize(new FrameSizeLimit(10000, 10000, 30))) .SetAllowDiskCaching(true) .AddCommandDefault("down.filter", "mitchell") .AddWatermark( new NamedWatermark("lb-corner-logo", "/img/londonbikers-logo-trans.png", new WatermarkOptions() .SetFitBoxLayout(new WatermarkFitBox(WatermarkAlign.Image, 10, 10, 90, 90), WatermarkConstraintMode.Within, new ConstraintGravity(100, 100)) .SetOpacity(0.7f) .SetHints(new ResampleHints() .SetResampleFilters(InterpolationFilter.Robidoux_Sharp, null) .SetSharpen(7, SharpenWhen.Downscaling)) .SetMinCanvasSize(800, 600))).AddWatermarkingHandler("/i", args => { if (args.Query.TryGetValue("water", out var value) && value == "mark") { args.AppliedWatermarks.Add(new NamedWatermark(null, "/img/londonbikers-logo-trans.png", new WatermarkOptions())); } }));

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/imazen/imageflow-dotnet-server/issues/22, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2LH2XHQH5MBNJSX7ZVDTSDDDLJANCNFSM4QO4POPQ .

JayVDZ commented 4 years ago

Yes, that did it, thank you @lilith 👍

.MapPath("/local-images", Path.Combine(env.WebRootPath, "img"))