void files_FileMoved(object sender, FileEventArgs e) { if (!Enabled) { return; } if (!IsResizableImagePath(e.VirtualPath)) { return; } foreach (ImageSizeElement size in images.Sizes.AllElements) { string source = ImagesUtility.GetResizedPath(e.SourcePath, size.Name); if (files.FileExists(source)) { string destination = ImagesUtility.GetResizedPath(e.VirtualPath, size.Name); if (!files.FileExists(destination)) { files.MoveFile(source, destination); } } } }
private void BuildImageSizes(List <FileData> preExistingFiles, string commaSeparatedListOfSizes) { if (string.IsNullOrEmpty(commaSeparatedListOfSizes)) { return; } foreach (var s in commaSeparatedListOfSizes.Split(',')) { ImageSizeElement size; if (!ConfiguredSizes.TryGetValue(s, out size)) { continue; } if (size.Height == 0 && size.Width == 0) { continue; } foreach (var file in preExistingFiles) { Response.Write("<div class='processed-image'>Creating " + file.VirtualPath + "</div>"); var originalPath = ImagesUtility.GetResizedPath(file.VirtualPath, "original"); var sourcePath = Fs.FileExists(originalPath) ? originalPath : file.VirtualPath; Resizer.CreateSize(file.VirtualPath, Resizer.GetImageBytes(sourcePath), size); } } }
void files_FileCopied(object sender, FileEventArgs e) { if (!Enabled) { return; } if (IsResizedPath(e.VirtualPath)) { return; } foreach (ImageSizeElement size in images.Sizes.AllElements) { Url sourceUrl = e.SourcePath; Url destinationUrl = e.VirtualPath; string sourcePath = ImagesUtility.GetResizedPath(sourceUrl, size.Name); if (!files.FileExists(sourcePath)) { continue; } string destinationPath = ImagesUtility.GetResizedPath(destinationUrl, size.Name); if (!files.FileExists(destinationPath)) { files.CopyFile(sourcePath, destinationPath); } } }
private string GetReizedUrl(IFileSystem fs, string imageSize) { string resizedUrl = ImagesUtility.GetResizedPath(ImageUrl, imageSize); if (fs.FileExists(resizedUrl)) { return(resizedUrl); } return(ImageUrl); }
void files_FileWritten(object sender, FileEventArgs e) { if (!IsResizableImagePath(e.VirtualPath)) { return; } if (images.Sizes.Count == 0) { return; } byte[] image; using (var s = files.OpenFile(e.VirtualPath)) { image = new byte[s.Length]; s.Read(image, 0, image.Length); } foreach (ImageSizeElement size in images.Sizes.AllElements) { if (!size.ResizeOnUpload) { continue; } Url url = e.VirtualPath; string resizedPath = ImagesUtility.GetResizedPath(url, size.Name); using (var sourceStream = new MemoryStream(image)) { if (size.Width <= 0 && size.Height <= 0) { using (var destinationStream = files.OpenFile(resizedPath)) { int b; while ((b = sourceStream.ReadByte()) != -1) { destinationStream.WriteByte((byte)b); } } } else { if (!files.FileExists(resizedPath) || size.Replace) { using (var destinationStream = files.OpenFile(resizedPath)) { resizer.Resize(sourceStream, url.Extension, size.Width, size.Height, size.Mode, destinationStream); } } } } } }
public virtual void CreateSize(Url virtualPath, byte[] image, ImageSizeElement size) { if (!size.ResizeOnUpload) { return; } string resizedPath = ImagesUtility.GetResizedPath(virtualPath, size.Name); using (var sourceStream = new MemoryStream(image)) { if (size.Width <= 0 && size.Height <= 0) { using (var destinationStream = files.OpenFile(resizedPath)) { int b; while ((b = sourceStream.ReadByte()) != -1) { destinationStream.WriteByte((byte)b); } } } else { // Delete the image before writing. // Fixes a weird bug where overwriting the original file while it still exists // leaves the resized image the with the exact same file size as the original even // though it should be smaller. if (files.FileExists(resizedPath)) { files.DeleteFile(resizedPath); } try { using (var destinationStream = files.OpenFile(resizedPath)) { resizer.Resize(sourceStream, new ImageResizeParameters(size.Width, size.Height, size.Mode) { Quality = size.Quality }, destinationStream); } } catch { } } } }
void files_FileDeleted(object sender, FileEventArgs e) { if (!IsResizableImagePath(e.VirtualPath)) { return; } foreach (ImageSizeElement size in images.Sizes.AllElements) { string resizedPath = ImagesUtility.GetResizedPath(e.VirtualPath, size.Name); if (files.FileExists(resizedPath)) { files.DeleteFile(resizedPath); } } }
private void RemoveImageSizes(List <FileData> preExistingFiles, string commaSeparatedListOfSizes) { if (string.IsNullOrEmpty(commaSeparatedListOfSizes)) { return; } foreach (var s in commaSeparatedListOfSizes.Split(',')) { foreach (var file in preExistingFiles) { var resizedPath = ImagesUtility.GetResizedPath(file.VirtualPath, s); if (Fs.FileExists(resizedPath)) { Response.Write("<div class='processed-image'>Removing " + file.Name + " - " + s + "</div>"); Fs.DeleteFile(resizedPath); } } } }
protected void OnUpdateCommand(object sender, CommandEventArgs args) { if (chkPermanentRedirect.Checked && previousParent != null) { var redirect = Engine.Resolve <ContentActivator>().CreateInstance <PermanentRedirect>(previousParent); redirect.Title = previousName + GetLocalResourceString("PermanentRedirect", " (permanent redirect)"); redirect.Name = previousName; redirect.RedirectUrl = Selection.SelectedItem.Url; redirect.RedirectTo = Selection.SelectedItem; redirect.AddTo(previousParent); Engine.Persister.Save(redirect); } tracker.UpdateReferencesTo(Selection.SelectedItem, previousUrl, isRenamingDirectory: Selection.SelectedItem is IFileSystemDirectory); if (Selection.SelectedItem is IFileSystemFile) { var sizes = this.Engine.Resolve <ImageSizeCache>().ImageSizes; foreach (var sizedImage in Selection.SelectedItem.Children) { var size = ImagesUtility.GetSize(sizedImage.Url, sizes); var previousSizeUrl = ImagesUtility.GetResizedPath(previousUrl, size); tracker.UpdateReferencesTo(sizedImage, previousSizeUrl, isRenamingDirectory: false); } } if (chkChildren.Checked) { mvPhase.ActiveViewIndex = 1; //rptDescendants.DataSource = Content.Search.Find.Where.AncestralTrail.Like(Selection.SelectedItem.GetTrail() + "%").Select() // .Where(Content.Is.Accessible()); rptDescendants.DataSource = Content.Search.Repository.Find(N2.Persistence.Parameter.Below(Selection.SelectedItem)).Where(Content.Is.Accessible()); rptDescendants.DataBind(); } else { Refresh(Selection.SelectedItem, ToolbarArea.Both); } }
void files_FileWritten(object sender, FileEventArgs e) { if (!IsResizableImagePath(e.VirtualPath)) { return; } if (images.Sizes.Count == 0) { return; } byte[] image; using (var s = files.OpenFile(e.VirtualPath)) { image = new byte[s.Length]; s.Read(image, 0, image.Length); } foreach (ImageSizeElement size in images.Sizes.AllElements) { if (!size.ResizeOnUpload) { continue; } Url url = e.VirtualPath; string resizedPath = ImagesUtility.GetResizedPath(url, size.Name); using (var sourceStream = new MemoryStream(image)) { if (size.Width <= 0 && size.Height <= 0) { using (var destinationStream = files.OpenFile(resizedPath)) { int b; while ((b = sourceStream.ReadByte()) != -1) { destinationStream.WriteByte((byte)b); } } } else { if (!files.FileExists(resizedPath) || size.Replace) { // Delete the image before writing. // Fixes a weird bug where overwriting the original file while it still exists // leaves the resized image the with the exact same file size as the original even // though it should be smaller. if (files.FileExists(resizedPath)) { files.DeleteFile(resizedPath); } using (var destinationStream = files.OpenFile(resizedPath)) { resizer.Resize(sourceStream, new ImageResizeParameters(size.Width, size.Height, size.Mode) { Quality = size.Quality }, destinationStream); } } } } } }