diff --git a/src/ImageProcessor.Tests/RegularExpressionUnitTests.cs b/src/ImageProcessor.Tests/RegularExpressionUnitTests.cs index 938f3cf15..c9d2da462 100644 --- a/src/ImageProcessor.Tests/RegularExpressionUnitTests.cs +++ b/src/ImageProcessor.Tests/RegularExpressionUnitTests.cs @@ -132,11 +132,7 @@ public void TestResizeRegex() public void TestRotateRegex() { const string Querystring = "rotate=270"; - RotateLayer expected = new RotateLayer - { - Angle = 270, - BackgroundColor = Color.Transparent - }; + RotateLayer expected = new RotateLayer(270, Color.Transparent); Rotate rotate = new Rotate(); rotate.MatchRegexIndex(Querystring); diff --git a/src/ImageProcessor.Web/Caching/DiskCache.cs b/src/ImageProcessor.Web/Caching/DiskCache.cs index 5ad38d051..33d48d19f 100644 --- a/src/ImageProcessor.Web/Caching/DiskCache.cs +++ b/src/ImageProcessor.Web/Caching/DiskCache.cs @@ -304,7 +304,7 @@ internal async Task IsNewOrUpdatedFileAsync() /// internal async Task SetCachedLastWriteTimeAsync() { - // Create Action delegate for IsNewOrUpdatedFile. + // Create Action delegate for SetCachedLastWriteTime. return await TaskHelpers.Run(() => this.SetCachedLastWriteTime()); } diff --git a/src/ImageProcessor.Web/Properties/AssemblyInfo.cs b/src/ImageProcessor.Web/Properties/AssemblyInfo.cs index 17f097b7c..5d2325f20 100644 --- a/src/ImageProcessor.Web/Properties/AssemblyInfo.cs +++ b/src/ImageProcessor.Web/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("2.1.1.0")] -[assembly: AssemblyFileVersion("2.1.1.0")] +[assembly: AssemblyVersion("2.1.2.0")] +[assembly: AssemblyFileVersion("2.1.2.0")] diff --git a/src/ImageProcessor/ImageFactory.cs b/src/ImageProcessor/ImageFactory.cs index ea9891d8b..b9f710a55 100644 --- a/src/ImageProcessor/ImageFactory.cs +++ b/src/ImageProcessor/ImageFactory.cs @@ -184,7 +184,7 @@ public ImageFactory Load(string imagePath) } /// - /// Resets the ImageFactory to its original loaded state. + /// Resets the current image to its original loaded state. /// /// /// The current instance of the class. @@ -213,7 +213,6 @@ public ImageFactory Reset() return this; } - #region Manipulation /// /// Adds a query-string to the image factory to allow auto-processing of remote files. @@ -317,7 +316,7 @@ public ImageFactory Contrast(int percentage) } /// - /// Crops an image to the given coordinates. + /// Crops the current image to the given location and size. /// /// /// The containing the coordinates to crop the image to. @@ -338,7 +337,7 @@ public ImageFactory Crop(Rectangle rectangle) } /// - /// Applies a filter to an image. + /// Applies a filter to the current image. /// /// /// The name of the filter to add to the image. @@ -359,7 +358,7 @@ public ImageFactory Filter(string filterName) } /// - /// Flips an image either horizontally or vertically. + /// Flips the current image either horizontally or vertically. /// /// /// Whether to flip the image vertically. @@ -384,7 +383,7 @@ public ImageFactory Flip(bool flipVertically) } /// - /// Sets the output format of the image to the matching . + /// Sets the output format of the current image to the matching . /// /// The . to set the image to. /// @@ -401,7 +400,10 @@ public ImageFactory Format(ImageFormat imageFormat) } /// - /// Applies a filter to an image. + /// Alters the output quality of the current image. + /// + /// This method will only effect the output quality of jpeg images + /// /// /// A value between 1 and 100 to set the quality to. /// @@ -418,7 +420,7 @@ public ImageFactory Quality(int percentage) } /// - /// Resizes an image to the given dimensions. + /// Resizes the current image to the given dimensions. /// /// /// The containing the width and height to set the image to. @@ -517,7 +519,7 @@ public ImageFactory Vignette() } /// - /// Adds a text based watermark to the image + /// Adds a text based watermark to the current image. /// /// /// The containing the properties necessary to add diff --git a/src/ImageProcessor/Imaging/RotateLayer.cs b/src/ImageProcessor/Imaging/RotateLayer.cs index cdf5d75a1..bce5ff1fc 100644 --- a/src/ImageProcessor/Imaging/RotateLayer.cs +++ b/src/ImageProcessor/Imaging/RotateLayer.cs @@ -26,6 +26,34 @@ public RotateLayer() { this.BackgroundColor = Color.Transparent; } + + /// + /// Initializes a new instance of the class. + /// + /// + /// The angle at which to rotate the image. + /// + public RotateLayer(int angle) + { + this.Angle = angle; + this.BackgroundColor = Color.Transparent; + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// The angle at which to rotate the image. + /// + /// + /// The to set as the background color. + /// Used for image formats that do not support transparency + /// + public RotateLayer(int angle, Color backgroundColor) + { + this.Angle = angle; + this.BackgroundColor = backgroundColor; + } #endregion #region Properties diff --git a/src/ImageProcessor/Imaging/TextLayer.cs b/src/ImageProcessor/Imaging/TextLayer.cs index a98df299e..df367eaa3 100644 --- a/src/ImageProcessor/Imaging/TextLayer.cs +++ b/src/ImageProcessor/Imaging/TextLayer.cs @@ -14,7 +14,7 @@ namespace ImageProcessor.Imaging #endregion /// - /// Enacapsulates the properties required to add a layer of text to an image. + /// Encapsulates the properties required to add a layer of text to an image. /// public class TextLayer { diff --git a/src/ImageProcessor/Processors/Rotate.cs b/src/ImageProcessor/Processors/Rotate.cs index 480085aa5..831250700 100644 --- a/src/ImageProcessor/Processors/Rotate.cs +++ b/src/ImageProcessor/Processors/Rotate.cs @@ -100,21 +100,20 @@ public int MatchRegexIndex(string queryString) // Set the index on the first instance only. this.SortOrder = match.Index; - RotateLayer rotateLayer = new RotateLayer(); + RotateLayer rotateLayer; string toParse = match.Value; if (toParse.Contains("bgcolor")) { - rotateLayer.Angle = this.ParseAngle(toParse); - rotateLayer.BackgroundColor = this.ParseColor(toParse); + rotateLayer = new RotateLayer(this.ParseAngle(toParse), this.ParseColor(toParse)); } else { int degrees; int.TryParse(match.Value.Split('=')[1], out degrees); - rotateLayer.Angle = degrees; + rotateLayer = new RotateLayer(degrees); } this.DynamicParameter = rotateLayer; diff --git a/src/ImageProcessor/Properties/AssemblyInfo.cs b/src/ImageProcessor/Properties/AssemblyInfo.cs index a5f50e13d..c921411c0 100644 --- a/src/ImageProcessor/Properties/AssemblyInfo.cs +++ b/src/ImageProcessor/Properties/AssemblyInfo.cs @@ -32,6 +32,6 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("1.4.2.0")] -[assembly: AssemblyFileVersion("1.4.2.0")] +[assembly: AssemblyVersion("1.5.0.0")] +[assembly: AssemblyFileVersion("1.5.0.0")] diff --git a/src/Nuget/ImageProcessor.1.5.0.0.nupkg b/src/Nuget/ImageProcessor.1.5.0.0.nupkg new file mode 100644 index 000000000..ef69659f5 Binary files /dev/null and b/src/Nuget/ImageProcessor.1.5.0.0.nupkg differ diff --git a/src/Nuget/ImageProcessor.Web.2.1.2.0.nupkg b/src/Nuget/ImageProcessor.Web.2.1.2.0.nupkg new file mode 100644 index 000000000..1ac41e14e Binary files /dev/null and b/src/Nuget/ImageProcessor.Web.2.1.2.0.nupkg differ diff --git a/src/Test/Test/Controllers/HomeController.cs b/src/Test/Test/Controllers/HomeController.cs index 7751ac03f..001908d61 100644 --- a/src/Test/Test/Controllers/HomeController.cs +++ b/src/Test/Test/Controllers/HomeController.cs @@ -6,11 +6,16 @@ namespace Test.Controllers { + using System.Drawing; + using System.Drawing.Imaging; using System.IO; using System.Threading.Tasks; using System.Web.Hosting; + using ImageProcessor; using ImageProcessor.Helpers.Extensions; + using ImageProcessor.Imaging; + //using ImageProcessor.Web.Caching; public class HomeController : Controller @@ -22,6 +27,67 @@ public ActionResult Index() return View(); } + public ActionResult Upload() + { + return View(); + } + + [HttpPost] + public ActionResult Upload(HttpPostedFileBase file) + { + Stream upload = file.InputStream; + int quality = 70; + ImageFormat format = ImageFormat.Jpeg; + Size size460 = new Size(460, 0); + Size size320 = new Size(320, 0); + Size size240 = new Size(240, 0); + + // Make sure the directory exists as Image.Save will not work without an existing directory. + string outputPath = HostingEnvironment.MapPath("~/Resized"); + if (outputPath != null) + { + DirectoryInfo directoryInfo = new DirectoryInfo(outputPath); + + if (!directoryInfo.Exists) + { + directoryInfo.Create(); + } + + // Make the three file paths + string outputfile1 = Path.Combine(outputPath, "460px_" + file.FileName); + string outputfile2 = Path.Combine(outputPath, "320px_" + file.FileName); + string outputfile3 = Path.Combine(outputPath, "240px_" + file.FileName); + + using (MemoryStream inStream = new MemoryStream()) + { + // Copy the stream across. + upload.CopyTo(inStream); + + using (ImageFactory imageFactory = new ImageFactory()) + { + // Load, resize, set the format and quality and save an image. + imageFactory.Load(inStream) + .Format(format) + .Quality(quality) + .Resize(size460) + .Save(outputfile1) + .Reset() + .Format(format) + .Quality(quality) + .Resize(size320) + .Save(outputfile2) + .Reset() + .Format(format) + .Quality(quality) + .Resize(size240) + .Save(outputfile3); + } + } + } + + return View(); + } + public ActionResult About() { List images = new List(); diff --git a/src/Test/Test/Resized/240px_228406_276791782435436_815038966_n.jpg b/src/Test/Test/Resized/240px_228406_276791782435436_815038966_n.jpg new file mode 100644 index 000000000..79ed5e34d Binary files /dev/null and b/src/Test/Test/Resized/240px_228406_276791782435436_815038966_n.jpg differ diff --git a/src/Test/Test/Resized/240px_MSwanson - Wide Large - Rock 02.jpg b/src/Test/Test/Resized/240px_MSwanson - Wide Large - Rock 02.jpg new file mode 100644 index 000000000..155d03abc Binary files /dev/null and b/src/Test/Test/Resized/240px_MSwanson - Wide Large - Rock 02.jpg differ diff --git a/src/Test/Test/Resized/240px_Neck2-1.jpg b/src/Test/Test/Resized/240px_Neck2-1.jpg new file mode 100644 index 000000000..366b7cb8b Binary files /dev/null and b/src/Test/Test/Resized/240px_Neck2-1.jpg differ diff --git a/src/Test/Test/Resized/320px_228406_276791782435436_815038966_n.jpg b/src/Test/Test/Resized/320px_228406_276791782435436_815038966_n.jpg new file mode 100644 index 000000000..387d049a6 Binary files /dev/null and b/src/Test/Test/Resized/320px_228406_276791782435436_815038966_n.jpg differ diff --git a/src/Test/Test/Resized/320px_MSwanson - Wide Large - Rock 02.jpg b/src/Test/Test/Resized/320px_MSwanson - Wide Large - Rock 02.jpg new file mode 100644 index 000000000..54f1b5058 Binary files /dev/null and b/src/Test/Test/Resized/320px_MSwanson - Wide Large - Rock 02.jpg differ diff --git a/src/Test/Test/Resized/320px_Neck2-1.jpg b/src/Test/Test/Resized/320px_Neck2-1.jpg new file mode 100644 index 000000000..1bc7e6a8e Binary files /dev/null and b/src/Test/Test/Resized/320px_Neck2-1.jpg differ diff --git a/src/Test/Test/Resized/460px_228406_276791782435436_815038966_n.jpg b/src/Test/Test/Resized/460px_228406_276791782435436_815038966_n.jpg new file mode 100644 index 000000000..fc6a899b7 Binary files /dev/null and b/src/Test/Test/Resized/460px_228406_276791782435436_815038966_n.jpg differ diff --git a/src/Test/Test/Resized/460px_MSwanson - Wide Large - Rock 02.jpg b/src/Test/Test/Resized/460px_MSwanson - Wide Large - Rock 02.jpg new file mode 100644 index 000000000..8747ee661 Binary files /dev/null and b/src/Test/Test/Resized/460px_MSwanson - Wide Large - Rock 02.jpg differ diff --git a/src/Test/Test/Resized/460px_Neck2-1.jpg b/src/Test/Test/Resized/460px_Neck2-1.jpg new file mode 100644 index 000000000..05a0d33e2 Binary files /dev/null and b/src/Test/Test/Resized/460px_Neck2-1.jpg differ diff --git a/src/Test/Test/Test.csproj b/src/Test/Test/Test.csproj index b0c9b6fe6..7b2e3093f 100644 --- a/src/Test/Test/Test.csproj +++ b/src/Test/Test/Test.csproj @@ -136,6 +136,9 @@ + + + 10.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) diff --git a/src/Test/Test/Views/Home/Upload.cshtml b/src/Test/Test/Views/Home/Upload.cshtml new file mode 100644 index 000000000..cf077c2a4 --- /dev/null +++ b/src/Test/Test/Views/Home/Upload.cshtml @@ -0,0 +1,5 @@ +@using (Html.BeginForm("Upload", "Home", FormMethod.Post, new { enctype = "multipart/form-data" })) +{ + + +} \ No newline at end of file diff --git a/src/Test/Test/Web.config b/src/Test/Test/Web.config index e7c9d334c..f6e8b95f0 100644 --- a/src/Test/Test/Web.config +++ b/src/Test/Test/Web.config @@ -4,84 +4,84 @@ http://go.microsoft.com/fwlink/?LinkId=152368 --> - - - -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file