Esempio n. 1
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            sizes = Engine.Resolve<EditSection>().Images.Sizes;
            fs = Engine.Resolve<IFileSystem>();

            ImagesUtility.SplitImageAndSize(Selection.SelectedItem.Url, sizes.GetSizeNames(), out baseImagePath, out imageSize);
            originalImagePath = fs.GetExistingImagePath(baseImagePath, "original");

            size = sizes.FirstOrDefault(s => s.Name == imageSize);
        }
Esempio n. 2
0
		private void AddSize(string baseImagePath, ImageSizeElement size)
		{
			if (size == null)
				throw new ArgumentNullException("size");

			bool exists;
			var path = Fs.GetExistingImagePath(baseImagePath, size.Name, out exists);
			if (exists)
			{
				if (SelectedFile == null)
					throw new ArgumentNullException("SelectedFile");

				var file = (SelectedFile.Parent as File) ?? SelectedFile;
				var child = file.GetChild(VirtualPathUtility.GetFileName(path));

				AddSizeControl(size, path, file, child);
			}
		}
        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
					{
					}
				}
			}
		}
		private static string GetText(ImageSizeElement ise)
		{
			return ise.Name + " " + GetLengthText(ise.Width) + "," + GetLengthText(ise.Height);
		}
Esempio n. 5
0
		private void AddSizeControl(ImageSizeElement size, string path, File file, ContentItem child)
		{
			if (path == null)
				throw new ArgumentNullException("path");
			if (file == null)
				throw new ArgumentNullException("file");
			if (child == null)
				throw new ArgumentNullException("child");

			var hl = new HyperLink { ID = size.Name + "Size" };
			hl.NavigateUrl = "File.aspx?selected=" + child.Path;
			hl.Text = Utility.GetResourceString("ImageSizes", size.Name + ".Text") ?? (string.IsNullOrEmpty(size.Description) ? size.Name : size.Description);
			hl.Text += GetSizeText(size.Width, size.Height);
			hl.CssClass = "command";
			if (bgSizes == null)
				throw new ArgumentNullException("bgSizes");

			if (path == Selection.SelectedItem.Url)
				bgSizes.Controls.AddAt(0, hl);
			else
				bgSizes.Controls.Add(hl);
		}