Merge pull request #1854 from umbraco/temp-U4-9720

U4-9720 No more _thumb thumbnail file generation - all thumbnails should be generated via Image Processor
This commit is contained in:
Claus
2017-04-04 09:49:10 +02:00
committed by GitHub
12 changed files with 66 additions and 162 deletions

View File

@@ -31,6 +31,7 @@ namespace Umbraco.Core.IO
private long _folderCounter;
private bool _folderCounterInitialized;
[Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")]
private static readonly Dictionary<int, string> DefaultSizes = new Dictionary<int, string>
{
{ 100, "thumb" },
@@ -263,7 +264,7 @@ namespace Umbraco.Core.IO
var filename = Path.GetFileName(sourcepath);
var filepath = GetMediaPath(filename, content.Key, propertyType.Key);
this.CopyFile(sourcepath, filepath);
CopyThumbnails(sourcepath, filepath);
return filepath;
}
@@ -312,29 +313,17 @@ namespace Umbraco.Core.IO
}
}
// sets a file for the FileUpload property editor
// ie generates thumbnails and populates autofill properties
/// <summary>
/// Sets a file for the FileUpload property editor and populates autofill properties
/// </summary>
/// <param name="content"></param>
/// <param name="property"></param>
/// <param name="filepath"></param>
/// <param name="filestream"></param>
private void SetUploadFile(IContentBase content, Property property, string filepath, Stream filestream)
{
// check if file is an image (and supports resizing and thumbnails etc)
var extension = Path.GetExtension(filepath);
var isImage = IsImageFile(extension);
// specific stuff for images (thumbnails etc)
if (isImage)
{
using (var image = Image.FromStream(filestream))
{
// use one image for all
GenerateThumbnails(image, filepath, property.PropertyType);
_uploadAutoFillProperties.Populate(content, property.Alias, filepath, filestream, image);
}
}
else
{
// will use filepath for extension, and filestream for length
_uploadAutoFillProperties.Populate(content, property.Alias, filepath, filestream);
}
{
// will use filepath for extension, and filestream for length
_uploadAutoFillProperties.Populate(content, property.Alias, filepath, filestream);
}
#endregion
@@ -401,6 +390,7 @@ namespace Umbraco.Core.IO
// note: this does not find 'custom' thumbnails?
// will find _thumb and _big-thumb but NOT _custom?
[Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")]
public IEnumerable<string> GetThumbnails(string path)
{
var parentDirectory = Path.GetDirectoryName(path);
@@ -421,12 +411,14 @@ namespace Umbraco.Core.IO
DeleteThumbnails(path);
}
[Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")]
public void DeleteThumbnails(string path)
{
GetThumbnails(path)
.ForEach(x => base.DeleteFile(x));
}
[Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")]
public void CopyThumbnails(string sourcePath, string targetPath)
{
var targetPathBase = Path.GetDirectoryName(targetPath) ?? "";
@@ -479,6 +471,7 @@ namespace Umbraco.Core.IO
#region GenerateThumbnails
[Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")]
public IEnumerable<ResizedImage> GenerateThumbnails(
Image image,
string filepath,
@@ -500,6 +493,7 @@ namespace Umbraco.Core.IO
return GenerateThumbnails(image, filepath, additionalSizes);
}
[Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")]
public IEnumerable<ResizedImage> GenerateThumbnails(
Image image,
string filepath,
@@ -522,6 +516,7 @@ namespace Umbraco.Core.IO
.ToList(); // now
}
[Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")]
public IEnumerable<ResizedImage> GenerateThumbnails(
Stream filestream,
string filepath,
@@ -535,6 +530,7 @@ namespace Umbraco.Core.IO
}
}
[Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")]
public IEnumerable<ResizedImage> GenerateThumbnails(
Image image,
string filepath,
@@ -556,16 +552,19 @@ namespace Umbraco.Core.IO
#region GenerateResized - Generate at resized filepath derived from origin filepath
[Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")]
public ResizedImage GenerateResized(Image originImage, string originFilepath, string sizeName, int maxWidthHeight)
{
return GenerateResized(originImage, originFilepath, sizeName, maxWidthHeight, -1, -1);
}
[Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")]
public ResizedImage GenerateResized(Image originImage, string originFilepath, string sizeName, int fixedWidth, int fixedHeight)
{
return GenerateResized(originImage, originFilepath, sizeName, -1, fixedWidth, fixedHeight);
}
[Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")]
public ResizedImage GenerateResized(Image originImage, string originFilepath, string sizeName, int maxWidthHeight, int fixedWidth, int fixedHeight)
{
if (string.IsNullOrWhiteSpace(sizeName))
@@ -581,16 +580,19 @@ namespace Umbraco.Core.IO
#region GenerateResizedAt - Generate at specified resized filepath
[Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")]
public ResizedImage GenerateResizedAt(Image originImage, string resizedFilepath, int maxWidthHeight)
{
return GenerateResizedAt(originImage, resizedFilepath, maxWidthHeight, -1, -1);
}
[Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")]
public ResizedImage GenerateResizedAt(Image originImage, int fixedWidth, int fixedHeight, string resizedFilepath)
{
return GenerateResizedAt(originImage, resizedFilepath, -1, fixedWidth, fixedHeight);
}
[Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")]
public ResizedImage GenerateResizedAt(Image originImage, string resizedFilepath, int maxWidthHeight, int fixedWidth, int fixedHeight)
{
// target dimensions
@@ -699,6 +701,7 @@ namespace Umbraco.Core.IO
#region Inner classes
[Obsolete("This should no longer be used, image manipulation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")]
public class ResizedImage
{
public ResizedImage()

View File

@@ -96,8 +96,7 @@ namespace Umbraco.Core.Media
/// <param name="propertyTypeAlias">The property type alias.</param>
/// <param name="filepath">The filesystem-relative filepath, or null to clear properties.</param>
/// <param name="filestream">The stream containing the file data.</param>
/// <param name="image">The file data as an image object.</param>
public void Populate(IContentBase content, string propertyTypeAlias, string filepath, Stream filestream, Image image = null)
public void Populate(IContentBase content, string propertyTypeAlias, string filepath, Stream filestream)
{
if (content == null) throw new ArgumentNullException("content");
if (propertyTypeAlias == null) throw new ArgumentNullException("propertyTypeAlias");
@@ -110,7 +109,7 @@ namespace Umbraco.Core.Media
if (autoFillConfig == null) return; // nothing
// populate
Populate(content, autoFillConfig, filepath, filestream, image);
Populate(content, autoFillConfig, filepath, filestream);
}
/// <summary>
@@ -158,8 +157,7 @@ namespace Umbraco.Core.Media
/// <param name="autoFillConfig"></param>
/// <param name="filepath">The filesystem-relative filepath, or null to clear properties.</param>
/// <param name="filestream">The stream containing the file data.</param>
/// <param name="image">The file data as an image object.</param>
public void Populate(IContentBase content, IImagingAutoFillUploadField autoFillConfig, string filepath, Stream filestream, Image image = null)
public void Populate(IContentBase content, IImagingAutoFillUploadField autoFillConfig, string filepath, Stream filestream)
{
if (content == null) throw new ArgumentNullException("content");
if (autoFillConfig == null) throw new ArgumentNullException("autoFillConfig");
@@ -172,11 +170,7 @@ namespace Umbraco.Core.Media
else
{
var extension = (Path.GetExtension(filepath) ?? "").TrimStart('.');
Size? size;
if (image == null)
size = _mediaFileSystem.IsImageFile(extension) ? (Size?) _mediaFileSystem.GetDimensions(filestream) : null;
else
size = new Size(image.Width, image.Height);
var size = _mediaFileSystem.IsImageFile(extension) ? (Size?)_mediaFileSystem.GetDimensions(filestream) : null;
SetProperties(content, autoFillConfig, size, filestream.Length, extension);
}
}

View File

@@ -468,12 +468,7 @@ namespace Umbraco.Core.Services
/// <param name="filepath">The filesystem path to the media.</param>
void DeleteMediaFile(string filepath);
/// <summary>
/// Generates thumbnails.
/// </summary>
/// <param name="filepath">The filesystem-relative path to the original image.</param>
/// <param name="propertyType">The property type.</param>
/// <remarks>This should be obsoleted, we should not generate thumbnails.</remarks>
[Obsolete("This should no longer be used, thumbnail generation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")]
void GenerateThumbnails(string filepath, PropertyType propertyType);
}
}

View File

@@ -1431,6 +1431,7 @@ namespace Umbraco.Core.Services
_mediaFileSystem.DeleteFile(filepath, true);
}
[Obsolete("This should no longer be used, thumbnail generation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")]
public void GenerateThumbnails(string filepath, PropertyType propertyType)
{
using (var filestream = _mediaFileSystem.OpenFile(filepath))

View File

@@ -2,6 +2,7 @@
namespace Umbraco.Web.UI.Umbraco.Controls.Images
{
[Obsolete("This is no longer used and will be removed in future versions")]
public partial class ImageViewer : global::umbraco.controls.Images.ImageViewer
{
}

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Xml.XPath;
using Umbraco.Core.Configuration;
using Umbraco.Core.Media;
@@ -7,6 +8,7 @@ using Umbraco.Core;
namespace Umbraco.Web.Media.ImageUrlProviders
{
[Obsolete("IImageUrlProvider is no longer used and will be removed in future versions")]
public class ImageUrlProvider : IImageUrlProvider
{
public const string DefaultName = "umbracoUpload";

View File

@@ -30,16 +30,7 @@ namespace Umbraco.Web.PropertyEditors
baseEditor.Validators.Add(new UploadFileTypeValidator());
return new FileUploadPropertyValueEditor(baseEditor, MediaFileSystem);
}
/// <summary>
/// Creates the corresponding preValue editor.
/// </summary>
/// <returns>The corresponding preValue editor.</returns>
protected override PreValueEditor CreatePreValueEditor()
{
return new FileUploadPreValueEditor();
}
/// <summary>
/// Gets a value indicating whether a property is an upload field.
/// </summary>
@@ -143,100 +134,7 @@ namespace Umbraco.Web.PropertyEditors
else
MediaFileSystem.UploadAutoFillProperties.Populate(content, autoFillConfig, MediaFileSystem.GetRelativePath(svalue));
}
}
/// <summary>
/// A custom pre-val editor to ensure that the data is stored how the legacy data was stored in
/// </summary>
internal class FileUploadPreValueEditor : ValueListPreValueEditor
{
public FileUploadPreValueEditor()
{
var field = Fields.First();
field.Description = "Enter a max width/height for each thumbnail";
field.Name = "Add thumbnail size";
//need to have some custom validation happening here
field.Validators.Add(new ThumbnailListValidator());
}
/// <summary>
/// Format the persisted value to work with our multi-val editor.
/// </summary>
/// <param name="defaultPreVals"></param>
/// <param name="persistedPreVals"></param>
/// <returns></returns>
public override IDictionary<string, object> ConvertDbToEditor(IDictionary<string, object> defaultPreVals, PreValueCollection persistedPreVals)
{
var result = new List<PreValue>();
//the pre-values just take up one field with a semi-colon delimiter so we'll just parse
var dictionary = persistedPreVals.FormatAsDictionary();
if (dictionary.Any())
{
//there should only be one val
var delimited = dictionary.First().Value.Value.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
var i = 0;
result.AddRange(delimited.Select(x => new PreValue(i++, x)));
}
//the items list will be a dictionary of it's id -> value we need to use the id for persistence for backwards compatibility
return new Dictionary<string, object> { { "items", result.ToDictionary(x => x.Id, PreValueAsDictionary) } };
}
private IDictionary<string, object> PreValueAsDictionary(PreValue preValue)
{
return new Dictionary<string, object> { { "value", preValue.Value }, { "sortOrder", preValue.SortOrder } };
}
/// <summary>
/// Take the posted values and convert them to a semi-colon separated list so that its backwards compatible
/// </summary>
/// <param name="editorValue"></param>
/// <param name="currentValue"></param>
/// <returns></returns>
public override IDictionary<string, PreValue> ConvertEditorToDb(IDictionary<string, object> editorValue, PreValueCollection currentValue)
{
var result = base.ConvertEditorToDb(editorValue, currentValue);
//this should just be a dictionary of values, we want to re-format this so that it is just one value in the dictionary that is
// semi-colon delimited
var values = result.Select(item => item.Value.Value).ToList();
result.Clear();
result.Add("thumbs", new PreValue(string.Join(";", values)));
return result;
}
internal class ThumbnailListValidator : IPropertyValidator
{
public IEnumerable<ValidationResult> Validate(object value, PreValueCollection preValues, PropertyEditor editor)
{
var json = value as JArray;
if (json == null) yield break;
//validate each item which is a json object
for (var index = 0; index < json.Count; index++)
{
var i = json[index];
var jItem = i as JObject;
if (jItem == null || jItem["value"] == null) continue;
//NOTE: we will be removing empty values when persisting so no need to validate
var asString = jItem["value"].ToString();
if (asString.IsNullOrWhiteSpace()) continue;
int parsed;
if (int.TryParse(asString, out parsed) == false)
{
yield return new ValidationResult("The value " + asString + " is not a valid number", new[]
{
//we'll make the server field the index number of the value so it can be wired up to the view
"item_" + index.ToInvariantString()
});
}
}
}
}
}
}
#region Application event handler, used to bind to events on startup

View File

@@ -7,7 +7,8 @@ using Umbraco.Core;
namespace umbraco.controls.Images
{
public partial class ImageViewer : UserControl
[Obsolete("This is no longer used and will be removed in future versions")]
public partial class ImageViewer : UserControl
{
public ImageViewer()

View File

@@ -21,7 +21,8 @@ namespace umbraco.controls.Images
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
[ScriptService]
public class ImageViewerUpdater : System.Web.Services.WebService
[Obsolete("This is no longer used and will be removed in future versions")]
public class ImageViewerUpdater : System.Web.Services.WebService
{
/// <summary>

View File

@@ -6,10 +6,11 @@
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
namespace umbraco.presentation.umbraco.dialogs {
[Obsolete("This is no longer used and will be removed in future versions")]
public partial class mediaPicker {
/// <summary>

View File

@@ -7,10 +7,11 @@ using Umbraco.Core;
namespace umbraco
{
/// <summary>
/// Extension methods for umbraco.cms.businesslogic.media.Media
/// </summary>
public static class MediaExtensions
/// <summary>
/// Extension methods for umbraco.cms.businesslogic.media.Media
/// </summary>
[Obsolete("Obsolete, Use Umbraco.Core.Models.Media", false)]
public static class MediaExtensions
{
/// <summary>
/// Functionally similar to the XPath axis 'ancestor'
@@ -203,12 +204,13 @@ namespace umbraco
return string.Empty;
}
/// <summary>
/// Gets the image thumbnail URL.
/// </summary>
/// <param name="media">an umbraco.cms.businesslogic.media.Media object</param>
/// <returns></returns>
public static string GetImageThumbnailUrl(this Media media)
/// <summary>
/// Gets the image thumbnail URL.
/// </summary>
/// <param name="media">an umbraco.cms.businesslogic.media.Media object</param>
/// <returns></returns>
[Obsolete("This should no longer be used, thumbnail generation should be done via ImageProcessor, Umbraco no longer generates '_thumb' files for media")]
public static string GetImageThumbnailUrl(this Media media)
{
if (media.ContentType.Alias.Equals(Constants.Conventions.MediaTypes.Image))
{

View File

@@ -35,35 +35,38 @@ namespace umbraco.cms.businesslogic.Files
#endregion
#region Static Methods
//MB: Do we really need all these overloads? looking through the code, only one of them is actually used
[Obsolete("This is no longer used and will be removed in future versions")]
public static UmbracoFile Save(HttpPostedFile file, string path)
{
return new UmbracoFile(UmbracoMediaFile.Save(file.InputStream, path));
}
[Obsolete("This is no longer used and will be removed in future versions")]
public static UmbracoFile Save(HttpPostedFileBase file, string path)
{
return new UmbracoFile(UmbracoMediaFile.Save(file.InputStream, path));
}
[Obsolete("This is no longer used and will be removed in future versions")]
public static UmbracoFile Save(Stream inputStream, string path)
{
return new UmbracoFile(UmbracoMediaFile.Save(inputStream, path));
}
[Obsolete("This is no longer used and will be removed in future versions")]
public static UmbracoFile Save(byte[] file, string relativePath)
{
return new UmbracoFile(UmbracoMediaFile.Save(new MemoryStream(file), relativePath));
}
[Obsolete("This is no longer used and will be removed in future versions")]
public static UmbracoFile Save(HttpPostedFile file)
{
return new UmbracoFile(UmbracoMediaFile.Save(file));
}
//filebase overload...
[Obsolete("This is no longer used and will be removed in future versions")]
public static UmbracoFile Save(HttpPostedFileBase file)
{
return new UmbracoFile(UmbracoMediaFile.Save(file));
@@ -118,11 +121,13 @@ namespace umbraco.cms.businesslogic.Files
return new System.Tuple<int, int>(size.Width, size.Height);
}
[Obsolete("This is no longer used and will be removed in future versions")]
public string Resize(int width, int height)
{
return _mediaFile.Resize(width, height);
}
[Obsolete("This is no longer used and will be removed in future versions")]
public string Resize(int maxWidthHeight, string fileNameAddition)
{
return _mediaFile.Resize(maxWidthHeight, fileNameAddition);