Merge remote-tracking branch 'origin/6.2.0' into 7.1.0
Conflicts: src/Umbraco.Core/Services/PackagingService.cs
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Web;
|
||||
using umbraco.editorControls.imagecropper;
|
||||
using Umbraco.Core.IO;
|
||||
//using Umbraco.Core.IO;
|
||||
|
||||
|
||||
namespace umbraco.editorControls.imagecropper
|
||||
{
|
||||
@@ -19,47 +21,34 @@ namespace umbraco.editorControls.imagecropper
|
||||
public string Path { get; set; }
|
||||
public string RelativePath { get; set; }
|
||||
|
||||
private readonly MediaFileSystem _fs;
|
||||
|
||||
public ImageInfo(string relativePath)
|
||||
{
|
||||
RelativePath = relativePath;
|
||||
Path = IOHelper.MapPath(relativePath);
|
||||
if (File.Exists(Path))
|
||||
_fs = FileSystemProviderManager.Current.GetFileSystemProvider<MediaFileSystem>();
|
||||
|
||||
try
|
||||
{
|
||||
string fileName = Path.Substring(Path.LastIndexOf('\\') + 1);
|
||||
Name = fileName.Substring(0, fileName.LastIndexOf('.'));
|
||||
RelativePath = relativePath;
|
||||
|
||||
byte[] buffer = null;
|
||||
|
||||
using (FileStream fs = new FileStream(Path, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
buffer = new byte[fs.Length];
|
||||
fs.Read(buffer, 0, (int) fs.Length);
|
||||
fs.Close();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
image = Image.FromStream(new MemoryStream(buffer));
|
||||
|
||||
Width = image.Width;
|
||||
Height = image.Height;
|
||||
Aspect = (float) Width/Height;
|
||||
DateStamp = File.GetLastWriteTime(Path);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Width = 0;
|
||||
Height = 0;
|
||||
Aspect = 0;
|
||||
}
|
||||
//This get's the IFileSystem's path based on the URL (i.e. /media/blah/blah.jpg )
|
||||
Path = _fs.GetRelativePath(relativePath);
|
||||
|
||||
image = Image.FromStream(_fs.OpenFile(Path));
|
||||
Name = _fs.GetFileName(Path);
|
||||
DateStamp = _fs.GetLastModified(Path).Date;
|
||||
Width = image.Width;
|
||||
Height = image.Height;
|
||||
Aspect = (float)Width / Height;
|
||||
|
||||
}
|
||||
else
|
||||
catch (Exception)
|
||||
{
|
||||
Width = 0;
|
||||
Height = 0;
|
||||
Aspect = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public bool Exists
|
||||
@@ -67,10 +56,10 @@ namespace umbraco.editorControls.imagecropper
|
||||
get { return Width > 0 && Height > 0; }
|
||||
}
|
||||
|
||||
public string Directory
|
||||
{
|
||||
get { return Path.Substring(0, Path.LastIndexOf('\\')); }
|
||||
}
|
||||
//public string Directory
|
||||
//{
|
||||
// get { return Path.Substring(0, Path.LastIndexOf('\\')); }
|
||||
//}
|
||||
|
||||
public void GenerateThumbnails(SaveData saveData, Config config)
|
||||
{
|
||||
@@ -78,18 +67,20 @@ namespace umbraco.editorControls.imagecropper
|
||||
{
|
||||
for (int i = 0; i < config.presets.Count; i++)
|
||||
{
|
||||
Crop crop = (Crop) saveData.data[i];
|
||||
Preset preset = (Preset) config.presets[i];
|
||||
Crop crop = (Crop)saveData.data[i];
|
||||
Preset preset = (Preset)config.presets[i];
|
||||
|
||||
// Crop rectangle bigger than actual image
|
||||
if(crop.X2 - crop.X > Width || crop.Y2 - crop.Y > Height)
|
||||
if (crop.X2 - crop.X > Width || crop.Y2 - crop.Y > Height)
|
||||
{
|
||||
crop = preset.Fit(this);
|
||||
}
|
||||
|
||||
var tmpName = Name.Substring(0, Name.LastIndexOf('.'));
|
||||
|
||||
ImageTransform.Execute(
|
||||
Path,
|
||||
String.Format("{0}_{1}", Name, preset.Name),
|
||||
String.Format("{0}_{1}", tmpName, preset.Name),
|
||||
crop.X,
|
||||
crop.Y,
|
||||
crop.X2 - crop.X,
|
||||
|
||||
@@ -2,35 +2,39 @@
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Drawing;
|
||||
using Umbraco.Core.IO;
|
||||
using System.IO;
|
||||
|
||||
|
||||
namespace umbraco.editorControls.imagecropper
|
||||
{
|
||||
[Obsolete("IDataType and all other references to the legacy property editors are no longer used this will be removed from the codebase in future versions")]
|
||||
public class ImageTransform
|
||||
{
|
||||
private static readonly MediaFileSystem _fs = FileSystemProviderManager.Current.GetFileSystemProvider<MediaFileSystem>();
|
||||
|
||||
public static void Execute(string sourceFile, string name, int cropX, int cropY, int cropWidth, int cropHeight, int sizeWidth, int sizeHeight, long quality)
|
||||
{
|
||||
if (!File.Exists(sourceFile)) return;
|
||||
|
||||
string path = sourceFile.Substring(0, sourceFile.LastIndexOf('\\'));
|
||||
if (!_fs.FileExists(sourceFile)) return;
|
||||
|
||||
|
||||
string path = string.Empty;
|
||||
|
||||
//http or local filesystem
|
||||
if (sourceFile.Contains("/"))
|
||||
path = sourceFile.Substring(0, sourceFile.LastIndexOf('/'));
|
||||
else
|
||||
path = sourceFile.Substring(0, sourceFile.LastIndexOf('\\'));
|
||||
|
||||
// TODO: Make configurable and move to imageInfo
|
||||
//if(File.Exists(String.Format(@"{0}\{1}.jpg", path, name))) return;
|
||||
|
||||
byte[] buffer = null;
|
||||
//Do we need this check as we are always working with images that are already in a folder??
|
||||
//DirectoryInfo di = new DirectoryInfo(path);
|
||||
//if (!di.Exists) di.Create();
|
||||
|
||||
using (FileStream fs = new FileStream(sourceFile, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
buffer = new byte[fs.Length];
|
||||
fs.Read(buffer, 0, (int)fs.Length);
|
||||
fs.Close();
|
||||
}
|
||||
|
||||
Image image = Image.FromStream(new MemoryStream(buffer));
|
||||
|
||||
DirectoryInfo di = new DirectoryInfo(path);
|
||||
if (!di.Exists) di.Create();
|
||||
Image image = Image.FromStream(_fs.OpenFile(sourceFile));
|
||||
|
||||
using (Image croppedImage = CropImage(image, new Rectangle(cropX, cropY, cropWidth, cropHeight)))
|
||||
{
|
||||
@@ -58,7 +62,13 @@ namespace umbraco.editorControls.imagecropper
|
||||
EncoderParameters encoderParams = new EncoderParameters(1);
|
||||
encoderParams.Param[0] = qualityParam;
|
||||
|
||||
img.Save(path, jpegCodec, encoderParams);
|
||||
var fileStream = new MemoryStream();
|
||||
|
||||
img.Save(fileStream, jpegCodec, encoderParams);
|
||||
fileStream.Position = 0;
|
||||
_fs.AddFile(path, fileStream, true);
|
||||
//just to be sure
|
||||
fileStream.Dispose();
|
||||
}
|
||||
|
||||
private static ImageCodecInfo GetEncoderInfo(string mimeType)
|
||||
|
||||
Reference in New Issue
Block a user