Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for SVG images #879

Closed
CrossBound opened this issue Oct 26, 2019 · 14 comments
Closed

Support for SVG images #879

CrossBound opened this issue Oct 26, 2019 · 14 comments

Comments

@CrossBound
Copy link

I've added SVG as an image type but the manager will not let me upload it. Is there a way around this?

            // add supported image type
            Piranha.App.MediaTypes.Images.Add(".svg", "image/svg+xml");

image

@tidyui
Copy link
Member

tidyui commented Oct 27, 2019

I haven’t tried it myself but it looks like the external imagesharp component can’t handle svg images. I’ll take a look at if there’s any updates on their library or if maybe skiasharp handles svg.

@mikaellindemann
Copy link
Contributor

I don't see why SVGs should be handled by the image cropper - most browsers are able to render them just fine in any resolution.

@tidyui
Copy link
Member

tidyui commented Oct 27, 2019

I’ll have check the code why it’s failing. My guess is that the content is added as an image so it uses the current image component to verify that it is an image which fails. We would probably need to extend the registration of image types so you can specify if it should be cropped or not.

@tidyui
Copy link
Member

tidyui commented Oct 27, 2019

So the problem is the following line in the code. When an image is uploaded it tries to create an Image object from it to get the dimensions of it:

_processor.GetSize(bytes, out width, out height);

As ImageSharp doesn't support opening svg files it throws an exception. So in order to support it we need to be able to bypass image processing for certain added image types.

@tidyui tidyui added this to the Version 7.1 milestone Oct 27, 2019
@tidyui tidyui closed this as completed in 4b1c8e0 Oct 27, 2019
@tidyui
Copy link
Member

tidyui commented Oct 27, 2019

This will be release in 7.1 you can now add a media type that doesn't support processing with:

Piranha.App.MediaTypes.Images.Add(".svg", "image/svg+xml", false);

All calls for getting a resized version of the image will return the original URL.

@tidyui tidyui self-assigned this Oct 30, 2019
@kttary
Copy link

kttary commented Jan 28, 2021

svg

where do you put this line of code?

@tidyui
Copy link
Member

tidyui commented Jan 28, 2021

In the Configure method in Startup.cs after App.Init() has been called. https://piranhacms.org/docs/master/content/media

Regards

@kttary
Copy link

kttary commented Jan 28, 2021

it keep saying

Failed to upload media. Image cannot be loaded. Available decoders:

  • JPEG : JpegDecoder
  • BMP : BmpDecoder
  • PNG : PngDecoder
  • GIF : GifDecoder
  • TGA : TgaDecoder

@tidyui
Copy link
Member

tidyui commented Jan 28, 2021

Which version are you using of Piranha? I haven't tested this for a while, I'll have to double-check so that our external dependency ImageSharp hasn't removed support for .svg in some upgrade.

@kttary
Copy link

kttary commented Jan 28, 2021

Piranha 8.4.1

@tidyui
Copy link
Member

tidyui commented Jan 28, 2021

@kttary Can you verify that you have set the third optional parameter to false when adding svg images, like so:

Piranha.App.MediaTypes.Images.Add(".svg", "image/svg+xml", false);

If not the file will be opened with ImageSharp to determine width & height, and .svg images is not supported by ImageSharp.

@kttary
Copy link

kttary commented Jan 28, 2021

Yes i follow your comment on oct 28 2019.

@tidyui
Copy link
Member

tidyui commented Jan 28, 2021

I can't reproduce your issue. I have done the following.

  1. Create a new web project with dotnet new piranha.razor
  2. Add the content type directly below App.Init(api) in Configure() in Startup.cs
  3. Restore, build and run the application
  4. Seed some test data for the template
  5. Login to the manager and navigate to the media library
  6. Drop a test .svg image in the upload panel

The file uploads correctly and I can open it and look at the details and preview (see screenshot).

Skärmavbild 2021-01-28 kl  15 33 24

The file used for testing was downloaded here:

https://commons.wikimedia.org/wiki/File:Test.svg

@kttary
Copy link

kttary commented Jan 29, 2021

Got it work now. Problem with my browser i think

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants