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

v10: Update to ImageSharp v2 #12185

Merged
merged 22 commits into from
Apr 29, 2022
Merged

v10: Update to ImageSharp v2 #12185

merged 22 commits into from
Apr 29, 2022

Conversation

ronaldbarendse
Copy link
Contributor

@ronaldbarendse ronaldbarendse commented Mar 28, 2022

Prerequisites

  • I have added steps to test this contribution in the description below

If there's an existing issue for this PR then this fixes #11329. Also see the related discussion #11938 and the draft PR #11991 trying to update v9 in a backwards compatible way (spoiler: we can't).

Description

This PR updates the dependency versions of ImageSharp to 2.1.0 and ImageSharp.Web to 2.0.0 (alpha, currently waiting on the final release). Because these new major versions contain breaking changes, we can only update these for the upcoming Umbraco v10 release. Some of the breaking changes are:

  • CachedNameLength has been renamed to CacheHashLength;
  • IDictionary<string, string> commands has been changed to CommandCollection commands;
  • A new RequiresTrueColorPixelFormat() method is added to IImageWebProcessor.

ImageSharp/ImageSharp.Web also has some functional changes as well:

  • The PhysicalFileSystemProvider doesn't use the WebRootFileProvider anymore (it now only supports actual physical files OOTB) (an additional WebRootImageProvider is now available OOTB, but not used by default);
  • The ResizeWebProcessor is now EXIF-orientation aware (as browsers now default to displaying images based on the EXIF orientation);
  • The PhysicalFileSystemCache has a separate option for the cache folder depth (it previously used the file length to create nested cache folders);
  • It adds support for WebP images and includes better memory management.

To-do:

@Nuklon

This comment was marked as off-topic.

@JimBobSquarePants

This comment was marked as off-topic.

@Nuklon

This comment was marked as off-topic.

@nul800sebastiaan nul800sebastiaan linked an issue Apr 25, 2022 that may be closed by this pull request
@@ -23,7 +23,7 @@ public class ContentImagingSettings
}
};

internal const string StaticImageFileTypes = "jpeg,jpg,gif,bmp,png,tiff,tif";
internal const string StaticImageFileTypes = "jpeg,jpg,gif,bmp,png,tiff,tif,webp";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This setting doesn't seem to be used: the supported image file types are now retrieved from the IImageUrlGenerator.SupportedImageFileTypes property and the ImageSharpImageUrlGenerator implementation dynamically retrieves the supported ones from the ImageSharp configuration instead.

These image file types are then used to for more then just generating image URLs though (e.g. whether to extract image dimensions to auto-fill properties, disallow file uploads that are not images and automatically changing the media type from File to Image).

I suggest keeping this setting and create a separate PR to fix the mixed usage, so:

  • ContentImagingSettings.ImageFileTypes is used to determine whether the uploaded file is a valid image and if it can automatically change the media type to Image;
  • IImageUrlGenerator.SupportedImageFileTypes is used whether it can generate an image URL for a specified file;
  • A new IImageDimensionExtractor.SupportedImageFileTypes property is added that exposes whether it can get dimensions for a specified file (and have the ImageSharpDimensionExtractor populate this the same way as the ImageSharpImageUrlGenerator currently does).


if (options.CacheBusterValue is string cacheBusterValue && !string.IsNullOrWhiteSpace(cacheBusterValue))
{
queryString.Add("rnd", cacheBusterValue);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think v would be a much better (and shorter) query string key, as this isn't a random value we're adding, but a versioning value. Changing this doesn't impact the generation of images: it would only invalidate any images in your browser cache.

And that might actually be for the better, as you should also clear your existing ImageSharp cache as part of the migration, because newly generated images can be different because of the automatic EXIF rotation.

Suggested change
queryString.Add("rnd", cacheBusterValue);
queryString.Add("v", cacheBusterValue);

This should then also be updated in the corresponding tests.

@ronaldbarendse ronaldbarendse marked this pull request as ready for review April 28, 2022 11:41
@ronaldbarendse
Copy link
Contributor Author

Breaking changes

  • Update dependency versions:
    • SixLabors.ImageSharp from 1.0.4 to 2.1.1 (see breaking changes in v2.0.0 release notes);
    • SixLabors.ImageSharp.Web from 1.0.5 to 2.0.0 (see breaking changed in release notes);
  • Renamed CachedNameLength property to CacheHashLength on ImagingCacheSettings;
  • Moved ImageSharpImageUrlGenerator from project Umbraco.Infrastructure to Umbraco.Web.Common and updated the corresponding namespace and DI registration (from AddCoreInitialServices() to AddUmbracoImageSharp());
  • Moved ImageSharp configuration from the AddUmbracoImageSharp() extension method into separate IConfigureOptions<> implementations:
    • The middleware is configured in ConfigureImageSharpMiddlewareOptions (which also replaces ImageSharpConfigurationOptions that previously only set the default ImageSharp configuration);
    • The default physical cache is configured in ConfigurePhysicalFileSystemCacheOptions.

There are also some functional changes to be aware of:

  • The default physical file cache has a different/optimized folder structure (less nesting and shorter file names): make sure to delete your existing cache folder if you're upgrading (located in umbraco\Data\TEMP\MediaCache);
  • The cache key is now only generated based on the relative URL (it doesn't include the hostname anymore), so the same cached image is returned if you have multiple hostnames configured in Umbraco;
  • Images are automatically rotated based on their EXIF orientation (another reason to remove your existing cached images);
  • WebP support is added 🎉

@@ -200,7 +200,6 @@ public static IUmbracoBuilder AddCoreInitialServices(this IUmbracoBuilder builde
// Add default ImageSharp configuration and service implementations
builder.Services.AddSingleton(SixLabors.ImageSharp.Configuration.Default);
builder.Services.AddSingleton<IImageDimensionExtractor, ImageSharpDimensionExtractor>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally we add a NoopImpementation so you can boot Infrastructure without the web assemblies

@bergmania bergmania merged commit 1a82e08 into v10/dev Apr 29, 2022
@bergmania bergmania deleted the v10/feature/imagesharp2 branch April 29, 2022 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrade ImageSharp.Web to V2.0.0
4 participants