cloudinary / CloudinaryDotNet

Cloudinary DotNet library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for SVGs along with responsive breakpoints

opolo opened this issue · comments

commented

Feature request for Cloudinary .NET SDK

Support for SVGs together with responsive breakpoints in SDK

Explain your use case

The following code has always worked for us, when uploading files to cloudinary:
`protected async Task SaveFileAsync(string filepath, Stream fileStream)
{
if (filepath == null) throw new ArgumentNullException(nameof(filepath));
if (fileStream == null) throw new ArgumentNullException(nameof(fileStream));

        var filename = Guid.NewGuid().ToString();
        fileStream.Position = 0;
        var uploadParams = new ImageUploadParams()
        {
            File = new FileDescription(filename, fileStream),
            PublicId = $"{ServiceDomain}/{ServiceSubDomain}/{filepath.Trim('/')}/{filename}",
            ResponsiveBreakpoints =
            new List<ResponsiveBreakpoint> { new ResponsiveBreakpoint().CreateDerived(true).MaxWidth(2000) }
        };
        var uploadResult = await _cloudinary.UploadAsync(uploadParams);
        var url = uploadResult.SecureUrl.ToString();
        return new Uri(url.Replace("/upload/", "/upload/c_scale,w_auto/"));
    }`

However, we have recently started using SVGs and are getting the following error, when trying to upload the SVG:
"Not encoding raster image to SVG, use e_vectorize as the last component in transformation"

Removing the responsive breakpoints lines stops this error. Is there any way we can have this working with SVGs? I looked into the SDK code, and saw no support for e_vectorize, so I dont know if its not a part of the .NET SDK.

Describe the problem you’re trying to solve

Uploading SVGs and have them eagerly transformed to their various sizes.

Do you have a proposed solution?

Not more in depth than requested above

Hi @opolo. Converting vector files while keeping them as vector requires the e_vectorize parameter, and as the error message says, it has to be in the last transformation component.
The Transformation option of ResponsiveBreakpoints is adding the transformation in the first component so setting e_vectorize there doesn't help.
I did manage to work around the issue by first setting the file's format to 'jpg' like this (thus rasterizing it):

Transformation transformation = new Transformation().FetchFormat("jpg");

...
...

ResponsiveBreakpoints =
                new List<ResponsiveBreakpoint> { new ResponsiveBreakpoint().CreateDerived(true).MaxWidth(2000).Transformation(transformation)}   

Will that work for you?

commented

Hi Roeeba!

Thanks for the response, this will work for the cases we were facing :) +1