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

Add default support for most common media formats. #1359

Closed
shapeh opened this issue Oct 11, 2020 · 4 comments
Closed

Add default support for most common media formats. #1359

shapeh opened this issue Oct 11, 2020 · 4 comments

Comments

@shapeh
Copy link

shapeh commented Oct 11, 2020

According to the docs - https://piranhacms.org/docs/content/media

The following are supported by default but perhaps it is time to include .gif, .webp and .jfif as common formats too (by default):

.jpg, .jpeg & .png images
.mp4 videos
.pdf documents

#237

We can do this:

Piranha.App.MediaTypes.Images.Add(".gif", "image/gif");
Piranha.App.MediaTypes.Images.Add(".jfif", "image/jpeg");
...

https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types

@tidyui
Copy link
Member

tidyui commented Oct 12, 2020

The reason we support the specified formats is that need to consider which formats are supported by ImageSharp, which is the library we currently use for scaling and cropping images.

https://docs.sixlabors.com/articles/imagesharp/imageformats.html

It appears by the documentation that they now supports .gif but we have deliberately stayed clear of .gif as we're not sure what will happen if one would try to attempt scaling operations on an animated gif. Still if someone would have time investigating this we could very well include it in the default file types. Currently .webp and .jfif seems to be unsupported.

@shapeh
Copy link
Author

shapeh commented Oct 12, 2020

Thanks for a quick reply:

I threw together a quick method to get all supported formats:

using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Processing;
using System;
    private static void GetFormats()
    {
        foreach (IImageFormat F in Configuration.Default.ImageFormats)
        {
            Console.Write($"  {F}  Mime Type: {F.DefaultMimeType}  Extension(s):  ");
            foreach (string ext in F.FileExtensions)
            {
                Console.Write($"{ext}  ");
            }
            Console.WriteLine();
        }
    }
  SixLabors.ImageSharp.Formats.Png.PngFormat  Mime Type: image/png  Extension(s):  png
  SixLabors.ImageSharp.Formats.Jpeg.JpegFormat  Mime Type: image/jpeg  Extension(s):  jpg  jpeg  jfif
  SixLabors.ImageSharp.Formats.Gif.GifFormat  Mime Type: image/gif  Extension(s):  gif
  SixLabors.ImageSharp.Formats.Bmp.BmpFormat  Mime Type: image/bmp  Extension(s):  bm  bmp  dip
  SixLabors.ImageSharp.Formats.Tga.TgaFormat  Mime Type: image/tga  Extension(s):  tga  vda  icb  vst

jfif, jpeg and jpg are all the same. If you look at the header of a jpg/jpeg/jfif file you will see JFIF.
It seems there a few more supported formats - Bitmaps and the TgaFormats (tga, vda, icb and vst) - can't say I have ever used the Tga's but why not support them when ImageSharp does.

As for .webp - yeah, it seems ImageSharp does not support it yet.

As for .gif - it also works fine with resizing (although coloring in this example seems to be a bit off - could probably be corrected):

    private static void Resize()
    {
        using (Image image = Image.Load("animated.gif"))
        {
            image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2));
            image.Save("resized.gif");
        }
    }

animated
resized

@tidyui tidyui added this to the Version 9.1 milestone Dec 22, 2020
@tidyui tidyui self-assigned this Apr 29, 2021
@tidyui tidyui closed this as completed in 08ed259 Apr 29, 2021
@magnuskarlssonhm
Copy link

Hey! Imagesharp supports webp now :) Reopen?
https://docs.sixlabors.com/articles/imagesharp/imageformats.html

@tidyui
Copy link
Member

tidyui commented Aug 28, 2022

@magnuskarlssonhm I think perhaps we should open a new issue for .webp support as this issue was released in 9.1

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

3 participants