public void Test_Gif_1() { GifFormat.Model gifModel; var fn = @"Targets\Singles\pic300x301.gif"; var file = new FileInfo(fn); using (var fs = new FileStream(fn, FileMode.Open, FileAccess.Read)) { var hdr = new byte[0x20]; var got = fs.Read(hdr, 0, hdr.Length); Assert.AreEqual(hdr.Length, got); gifModel = GifFormat.CreateModel(fs, hdr, fs.Name); Assert.IsNotNull(gifModel); } GifFormat gif = gifModel.Data; Assert.AreEqual(300, gif.Width); Assert.AreEqual(301, gif.Height); Assert.IsTrue(gif.Issues.MaxSeverity == Severity.NoIssue); Assert.AreEqual(0, gif.Issues.Items.Count); }
//ExEnd:SourceGifFilePath /// <summary> ///Gets XMP properties of Gif file /// </summary> public static void GetXMPProperties() { try { //ExStart:GetXMPPropertiesGifImage // initialize GifFormat GifFormat gifFormat = new GifFormat(Common.MapSourceFilePath(filePath)); if (gifFormat.IsSupportedXmp) { // get XMP data XmpProperties xmpProperties = gifFormat.GetXmpProperties(); // show XMP data foreach (string key in xmpProperties.Keys) { XmpNodeView xmpNodeView = xmpProperties[key]; Console.WriteLine("[{0}] = {1}", xmpNodeView.Name, xmpNodeView.Value); } } //ExEnd:GetXMPPropertiesGifImage } catch (Exception exp) { Console.WriteLine(exp.Message); } }
private ISupportedImageFormat GetFormat(string extension, ImageInstruction ins) { ISupportedImageFormat format = null; if (extension.Equals(".jpg", StringComparison.OrdinalIgnoreCase) || extension.Equals(".jpeg", StringComparison.OrdinalIgnoreCase)) { format = new JpegFormat { Quality = ins.JpegQuality } } ; else if (extension.Equals(".gif", StringComparison.OrdinalIgnoreCase)) { format = new GifFormat { } } ; else if (extension.Equals(".png", StringComparison.OrdinalIgnoreCase)) { format = new PngFormat { } } ; return(format); }
/// <summary> /// Updates XMP data of Gif file and creates output file /// </summary> public static void UpdateXMPProperties() { try { //ExStart:UpdateXMPPropertiesGifImage // initialize GifFormat GifFormat gifFormat = new GifFormat(Common.MapSourceFilePath(filePath)); if (gifFormat.IsSupportedXmp) { // get xmp wrapper XmpPacketWrapper xmpPacket = gifFormat.GetXmpData(); // create xmp wrapper if not exists if (xmpPacket == null) { xmpPacket = new XmpPacketWrapper(); } // check if DublinCore schema exists if (!xmpPacket.ContainsPackage(Namespaces.DublinCore)) { // if not - add DublinCore schema xmpPacket.AddPackage(new DublinCorePackage()); } // get DublinCore package DublinCorePackage dublinCorePackage = (DublinCorePackage)xmpPacket.GetPackage(Namespaces.DublinCore); string authorName = "New author"; string description = "New description"; string subject = "New subject"; string publisher = "New publisher"; string title = "New title"; // set author dublinCorePackage.SetAuthor(authorName); // set description dublinCorePackage.SetDescription(description); // set subject dublinCorePackage.SetSubject(subject); // set publisher dublinCorePackage.SetPublisher(publisher); // set title dublinCorePackage.SetTitle(title); // update XMP package gifFormat.SetXmpData(xmpPacket); // commit changes gifFormat.Save(Common.MapDestinationFilePath(filePath)); } //ExEnd:UpdateXMPPropertiesGifImage Console.WriteLine("File saved in destination folder."); } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Processes the loaded image. Inheritors should NOT save the image, this is done by the main method. /// </summary> /// <param name="query">Query</param> /// <param name="processor">Processor instance</param> protected virtual void ProcessImageCore(ProcessImageQuery query, ImageFactory processor) { // Resize var size = query.MaxWidth != null || query.MaxHeight != null ? new Size(query.MaxWidth ?? 0, query.MaxHeight ?? 0) : Size.Empty; if (!size.IsEmpty) { processor.Resize(new ResizeLayer( size, resizeMode: ConvertScaleMode(query.ScaleMode), anchorPosition: ConvertAnchorPosition(query.AnchorPosition), upscale: false)); } if (query.BackgroundColor.HasValue()) { processor.BackgroundColor(ColorTranslator.FromHtml(query.BackgroundColor)); } // Format if (query.Format != null) { var format = query.Format as ISupportedImageFormat; if (format == null && query.Format is string) { var requestedFormat = ((string)query.Format).ToLowerInvariant(); switch (requestedFormat) { case "jpg": case "jpeg": format = new JpegFormat(); break; case "png": format = new PngFormat(); break; case "gif": format = new GifFormat(); break; } } if (format != null) { processor.Format(format); } } // Set Quality if (query.Quality.HasValue) { processor.Quality(query.Quality.Value); } }
public void GetGif() { var expected = new GifFormat(); var i = new Imaging(); foreach (var extension in expected.FileExtensions) { var format = i.Get(extension); Assert.AreEqual(expected.GetType(), format.GetType()); } }
public void GetNegativeQuality() { var expected = new GifFormat(); var i = new Imaging(); foreach (var extension in expected.FileExtensions) { var format = i.Get(extension, -45); Assert.AreEqual(Imaging.DefaultImageQuality, format.Quality); } }
private ISupportedImageFormat GetImageFormat(string filename) { ISupportedImageFormat format = null; String temp = filename; temp.ToLower(); if (temp.EndsWith(".png")) { format = new PngFormat { Quality = 70 } } ; if (temp.EndsWith(".gif")) { format = new GifFormat { Quality = 70 } } ; if (temp.EndsWith(".jpeg")) { format = new JpegFormat { Quality = 70 } } ; if (temp.EndsWith(".jpg")) { format = new JpegFormat { Quality = 70 } } ; if (format == null) { format = new JpegFormat { Quality = 70 }; } return(format); }
public void GetXMPData() { try { //ExStart:GetXMPData // create new instance of GifFormat GifFormat gif = new GifFormat(@"C:\sample.gif"); // old version of gif format does not support xmp if (!gif.IsSupportedXmp) { return; } // get XMP data XmpPacketWrapper xmp = gif.GetXmpData(); //ExEnd:GetXMPData } catch (Exception exp) { } }
private static void ProcessImage(string contentType, Stream input, Stream output, int quality, int maxWidth) { ISupportedImageFormat format = new JpegFormat { Quality = quality }; if (contentType == "image/gif") { format = new GifFormat { Quality = quality } } ; if (contentType == "image/png") { format = new PngFormat { Quality = quality } } ; var maxSize = new Size(maxWidth, 0); var resize = new ResizeLayer(maxSize, ResizeMode.Max, AnchorPosition.Center, false, null, maxSize); using (var memoryOutput = new MemoryStream()) { using (var imageFactory = new ImageFactory(preserveExifData: true)) { imageFactory.Load(input) .Resize(resize) .Format(format) .Save(memoryOutput); } memoryOutput.Seek(0, SeekOrigin.Begin); memoryOutput.CopyTo(output); } } } }
public void UnitGif_1() { var fName1 = @"Targets\Singles\pic300x301.gif"; GifFormat gif; using (Stream fs = new FileStream(fName1, FileMode.Open, FileAccess.Read)) { GifFormat.Model gifModel; var hdr = new byte[0x20]; var got = fs.Read(hdr, 0, hdr.Length); Assert.AreEqual(hdr.Length, got); gifModel = GifFormat.CreateModel(fs, hdr, fName1); gif = gifModel.Data; } Assert.AreEqual(300, gif.Width); Assert.AreEqual(301, gif.Height); Assert.AreEqual(Severity.NoIssue, gif.Issues.MaxSeverity); Assert.AreEqual(0, gif.Issues.Items.Count); }
/// <summary> /// Removes XMP data of Gif file and creates output file /// </summary> public static void RemoveXMPProperties() { try { //ExStart:RemoveXMPPropertiesGifImage // initialize GifFormat GifFormat gifFormat = new GifFormat(Common.MapSourceFilePath(filePath)); if (gifFormat.IsSupportedXmp) { // remove XMP package gifFormat.RemoveXmpData(); // commit changes gifFormat.Save(Common.MapDestinationFilePath(filePath)); } //ExEnd:RemoveXMPPropertiesGifImage Console.WriteLine("File saved in destination folder."); } catch (Exception exp) { Console.WriteLine(exp.Message); } }
public void ChangeFormat(MimeType type) { ISupportedImageFormat format; switch (type.Title) { case "image/bmp": format = new BitmapFormat(); break; case "image/jpeg": format = new JpegFormat(); break; case "image/png": format = new PngFormat(); break; case "image/tiff": format = new TiffFormat(); break; case "image/gif": format = new GifFormat(); break; default: throw new ArgumentException("Image format is not supported."); } this.FileName = Path.ChangeExtension(this.FileName, type.Extension); ChangeFormat(format); }
//ExEnd:ApplyLicense public static string CleanFile(string filePath) { try { try { //Apply license... ApplyLicense(); } catch (Exception exp) { MessageBox.Show("In Licence: " + exp.Message); } try { //Recognize format of file... FormatBase format = FormatFactory.RecognizeFormat(filePath); if (format.Type.ToString().ToLower() == "doc" || format.Type.ToString().ToLower() == "docx") { // initialize DocFormat... DocFormat docFormat = format as DocFormat; if (docFormat != null) { // get document properties... DocMetadata properties = new DocMetadata(); properties = docFormat.DocumentProperties; //Remove custom properties... foreach (KeyValuePair <string, PropertyValue> keyValuePair in properties) { if (!properties.IsBuiltIn(keyValuePair.Key)) { properties.Remove(keyValuePair.Key); } } //Reset built-in properties... properties.Author = ""; properties.Category = ""; properties.Comments = ""; properties.Company = ""; properties.ContentStatus = ""; properties.HyperlinkBase = ""; properties.Keywords = ""; properties.Manager = ""; properties.Title = ""; //Update metadata if file... MetadataUtility.UpdateMetadata(filePath, properties); } return("1"); } else if (format.Type.ToString().ToLower() == "xls" || format.Type.ToString().ToLower() == "xlsx") { //Initialize XlsFormat... XlsFormat xlsFormat = format as XlsFormat; if (xlsFormat != null) { //Get document properties... XlsMetadata properties = xlsFormat.DocumentProperties; //Remove custom properties... foreach (KeyValuePair <string, PropertyValue> keyValuePair in properties) { if (!properties.IsBuiltIn(keyValuePair.Key)) { properties.Remove(keyValuePair.Key); } } //Reset built-in properties... properties.Author = ""; properties.Category = ""; properties.Comments = ""; properties.Company = ""; properties.HyperlinkBase = ""; properties.Keywords = ""; properties.Manager = ""; properties.Title = ""; properties.Subject = ""; //Update metadata in files... MetadataUtility.UpdateMetadata(filePath, properties); } return("1"); } else if (format.Type.ToString().ToLower() == "ppt" || format.Type.ToString().ToLower() == "pptx") { //Initialize PptFormat... PptFormat pptFormat = format as PptFormat; if (pptFormat != null) { //Get document properties... PptMetadata properties = pptFormat.DocumentProperties; //Remove custom properties foreach (KeyValuePair <string, PropertyValue> keyValuePair in properties) { if (!properties.IsBuiltIn(keyValuePair.Key)) { properties.Remove(keyValuePair.Key); } } //Reset built-in properties... properties.Author = ""; properties.Category = ""; properties.Comments = ""; properties.Company = ""; properties.Keywords = ""; properties.Manager = ""; properties.Title = ""; properties.Subject = ""; //Update metadata of file... MetadataUtility.UpdateMetadata(filePath, properties); } return("1"); } else if (format.Type.ToString().ToLower() == "pdf") { // initialize PdfFormat... PdfFormat pdfFormat = format as PdfFormat; if (pdfFormat != null) { // get document properties... PdfMetadata properties = pdfFormat.DocumentProperties; // Remove custom properties... foreach (KeyValuePair <string, PropertyValue> keyValuePair in properties) { if (!properties.IsBuiltIn(keyValuePair.Key)) { properties.Remove(keyValuePair.Key); } } //Reset built-in properties... properties.Author = ""; properties.CreatedDate = DateTime.MinValue; properties.Keywords = ""; properties.ModifiedDate = DateTime.MinValue; properties.Subject = ""; properties.TrappedFlag = false; properties.Title = ""; //Update metadata of file... MetadataUtility.UpdateMetadata(filePath, properties); } return("1"); } else if (format.Type.ToString().ToLower() == "jpeg" || format.Type.ToString().ToLower() == "jpg") { //Get EXIF data if exists ExifMetadata exifMetadata = (ExifMetadata)MetadataUtility.ExtractSpecificMetadata(filePath, MetadataType.EXIF); //Get XMP data if exists XmpMetadata xmpMetadata = (XmpMetadata)MetadataUtility.ExtractSpecificMetadata(filePath, MetadataType.XMP); if (exifMetadata != null) { //Remove exif info... ExifInfo exifInfo = exifMetadata.Data; if (exifInfo.GPSData != null) { // set altitude, latitude and longitude to null values exifInfo.GPSData.Altitude = null; exifInfo.GPSData.Latitude = null; exifInfo.GPSData.LatitudeRef = null; exifInfo.GPSData.Longitude = null; exifInfo.GPSData.LongitudeRef = null; } exifInfo.BodySerialNumber = ""; exifInfo.CameraOwnerName = ""; exifInfo.CFAPattern = new byte[] { 0 }; } else { exifMetadata = new ExifMetadata(); } try { //Remove XMP data... XmpPacketWrapper xmpPacket = xmpMetadata.XmpPacket; if (xmpPacket != null) { if (xmpPacket.ContainsPackage(Namespaces.DublinCore)) { // if not - add DublinCore schema xmpPacket.AddPackage(new DublinCorePackage()); DublinCorePackage dublinCorePackage = (DublinCorePackage)xmpPacket.GetPackage(Namespaces.DublinCore); dublinCorePackage.Clear(); xmpMetadata.XmpPacket = xmpPacket; } } } catch { } //Update Exif info... try { MetadataUtility.UpdateMetadata(filePath, exifMetadata); } catch { } //Update XMP data... try { MetadataUtility.UpdateMetadata(filePath, xmpMetadata); } catch { } //Remove custom metadata if any... MetadataUtility.CleanMetadata(filePath); return("1"); } else if (format.Type.ToString().ToLower() == "png") { //Get XMP data... XmpMetadata xmpMetadata = (XmpMetadata)MetadataUtility.ExtractSpecificMetadata(filePath, MetadataType.XMP); try { //Remove XMP metadata... XmpPacketWrapper xmpPacket = xmpMetadata.XmpPacket; if (xmpPacket != null) { if (xmpPacket.ContainsPackage(Namespaces.DublinCore)) { // if not - add DublinCore schema xmpPacket.AddPackage(new DublinCorePackage()); DublinCorePackage dublinCorePackage = (DublinCorePackage)xmpPacket.GetPackage(Namespaces.DublinCore); dublinCorePackage.Clear(); xmpMetadata.XmpPacket = xmpPacket; //Update XMP metadata in file... MetadataUtility.UpdateMetadata(filePath, xmpMetadata); //Clean custom metadata if any... MetadataUtility.CleanMetadata(filePath); } } } catch { } return("1"); } else if (format.Type.ToString().ToLower() == "gif") { //Initialie GifFormat... GifFormat gifFormat = new GifFormat(filePath); //Check if Xmp supported... if (gifFormat.IsSupportedXmp) { //Get XMP data... XmpMetadata xmpMetadata = (XmpMetadata)MetadataUtility.ExtractSpecificMetadata(filePath, MetadataType.XMP); try { XmpPacketWrapper xmpPacket = xmpMetadata.XmpPacket; if (xmpPacket != null) { if (xmpPacket.ContainsPackage(Namespaces.DublinCore)) { // if not - add DublinCore schema xmpPacket.AddPackage(new DublinCorePackage()); DublinCorePackage dublinCorePackage = (DublinCorePackage)xmpPacket.GetPackage(Namespaces.DublinCore); dublinCorePackage.Clear(); xmpMetadata.XmpPacket = xmpPacket; //Update Xmp data in file... MetadataUtility.UpdateMetadata(filePath, xmpMetadata); //Clean custom metadata if any... MetadataUtility.CleanMetadata(filePath); } } } catch { } } return("1"); } else { return("Format not supported."); } } catch (Exception exp) { MessageBox.Show("Exception: " + exp.Message); return(exp.Message); } } catch (Exception exp) { return(exp.Message); } }
public ImagePreviewResponse Preview(string imageId, string containerName, string imageFormat, int brightness, int contrast, int saturation, int sharpness, bool sepia, bool polaroid, bool greyscale) { var response = new ImagePreviewResponse(); //Create the id for the enhanced "preview" version of the source image string enhancedImageId = Guid.NewGuid().ToString(); var outputFormatString = string.Empty; ISupportedImageFormat outputFormatProcessorProperty = null; System.Drawing.Imaging.ImageFormat outputFormatSystemrawingFormat = null; #region Select image format, or send error switch (imageFormat) { case "jpg": outputFormatString = ".jpg"; outputFormatProcessorProperty = new JpegFormat { Quality = 90 }; outputFormatSystemrawingFormat = System.Drawing.Imaging.ImageFormat.Jpeg; break; case "gif": outputFormatString = ".gif"; outputFormatProcessorProperty = new GifFormat { }; outputFormatSystemrawingFormat = System.Drawing.Imaging.ImageFormat.Gif; break; case "png": outputFormatString = ".png"; outputFormatProcessorProperty = new PngFormat { }; outputFormatSystemrawingFormat = System.Drawing.Imaging.ImageFormat.Png; break; case "bmp": outputFormatString = ".bmp"; outputFormatProcessorProperty = new BitmapFormat { }; outputFormatSystemrawingFormat = System.Drawing.Imaging.ImageFormat.Bmp; break; case "tiff": outputFormatString = ".tiff"; outputFormatProcessorProperty = new TiffFormat { }; outputFormatSystemrawingFormat = System.Drawing.Imaging.ImageFormat.Tiff; break; default: return(new ImagePreviewResponse { isSuccess = false, ErrorMessage = "Please please use a supported file format: jpg, png, gif, bmp or tiff." }); } #endregion #region verify all input parameters, or send error if ( brightness < -100 || brightness > 100 || sharpness < -100 || sharpness > 100 || contrast < -100 || contrast > 100 || saturation < -100 || saturation > 100 ) { return(new ImagePreviewResponse { isSuccess = false, ErrorMessage = "Please pass in a value between -100 and 100 for all enhancement parameters" }); } #endregion //Build out response object response.ImageID = enhancedImageId; response.FileName = enhancedImageId + outputFormatString; response.SourceFile = imageId + outputFormatString; #region Connect to Intermediary Storage // Credentials are from centralized CoreServiceSettings StorageCredentials storageCredentials = new StorageCredentials(CoreServices.PlatformSettings.Storage.IntermediaryName, CoreServices.PlatformSettings.Storage.IntermediaryKey); var storageAccount = new CloudStorageAccount(storageCredentials, false); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); #endregion try { //Pull down the source image as MemoryStream from Blob storage and apply image enhancement properties using (MemoryStream sourceStream = Common.GetAssetFromIntermediaryStorage(response.SourceFile, containerName, blobClient)) { #region Image Processor & Storage using (MemoryStream outStream = new MemoryStream()) { using (ImageFactory imageFactory = new ImageFactory()) { // Load, resize, set the format and quality and save an image. // Applies all in order... sourceStream.Position = 0; imageFactory.Load(sourceStream); if (brightness != 0) { imageFactory.Brightness(brightness); } if (contrast != 0) { imageFactory.Contrast(contrast); } if (saturation != 0) { imageFactory.Saturation(saturation); } //Sharpness if (sharpness != 0) { imageFactory.GaussianSharpen(sharpness); } //Filters if (sepia == true) { imageFactory.Filter(MatrixFilters.Sepia); } if (polaroid == true) { imageFactory.Filter(MatrixFilters.Polaroid); } if (greyscale == true) { imageFactory.Filter(MatrixFilters.GreyScale); } imageFactory.Save(outStream); } //Store each image size to BLOB STORAGE --------------------------------- #region BLOB STORAGE //Creat/Connect to the Blob Container //blobClient.GetContainerReference(containerName).CreateIfNotExists(BlobContainerPublicAccessType.Blob); //<-- Create and make public CloudBlobContainer blobContainer = blobClient.GetContainerReference(containerName); //Get reference to the picture blob or create if not exists. CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(response.FileName); //Save to storage //Convert final BMP to byteArray Byte[] finalByteArray; finalByteArray = outStream.ToArray(); //Store the enhanced "preview" into the same container as the soure blockBlob.UploadFromByteArray(finalByteArray, 0, finalByteArray.Length); #endregion } #endregion } } catch (Exception e) { return(new ImagePreviewResponse { isSuccess = false, ErrorMessage = e.Message }); } //Marke as successful and return the new ImageID and FileName back to the client for previewing: response.isSuccess = true; return(response); }
public DataAccessResponseType ProcessApplicationImage(string accountId, string storagePartition, string sourceContainerName, string sourceFileName, int formatWidth, int formatHeight, string folderName, string type, int quality, ImageCropCoordinates imageCropCoordinates, ImageEnhancementInstructions imageEnhancementInstructions) { //Create image id and response object string imageId = System.Guid.NewGuid().ToString(); var response = new DataAccessResponseType(); //var imageSpecs = Sahara.Core.Settings.Imaging.Images.ApplicationImage; //var setSizes = imageSpecs.SetSizes; //var folderName = imageSpecs.ParentName; //------------------------------------------------- // REFACTORING NOTES //------------------------------------------------- // In this scenario we have ApplicationImages hard coded to 600x300 for the LARGE size. We then create a medium and small dynmically (as well as a thumbnail hardcoded to 96px tall)(specific sizes can be factored in if required). // In extended scenarios we can pass these specs from CoreServices to clients via a call or from a Redis Cache or WCF fallback. // In scenarios where accounts have "Flexible Schemas" we can retreive these properties from a Redis or WCF call for each account based on that accounts set properties. //----------------------------------------------------------------------------- //var largeSize = new ApplicationImageSize{X=600, Y=300, Name="Large", NameKey = "large"}; //var mediumSize = new ApplicationImageSize { X = Convert.ToInt32(largeSize.X / 1.25), Y = Convert.ToInt32(largeSize.Y / 1.25), Name = "Medium", NameKey = "medium" }; //<-- Med is 1/1.25 of large //var smallSize = new ApplicationImageSize { X = largeSize.X / 2, Y = largeSize.Y / 2, Name = "Small", NameKey = "small" }; //<-- Small is 1/2 of large //We calculate thumbnail width based on a set height of 96px. //Must be a Double and include .0 in calculation or will ALWAYS calculate to 0! //double calculatedThumbnailWidth = ((96.0 / largeSize.Y) * largeSize.X); //<-- Must be a Double and include .0 or will calculate to 0! //var thumbnailSize = new ApplicationImageSize { X = (int)calculatedThumbnailWidth, Y = 96, Name = "Thumbnail", NameKey = "thumbnail" }; //<-- Thumbnail is 96px tall, width is calculated based on this //We are going to loop through each size during processing //var setSizes = new List<ApplicationImageSize> { largeSize, mediumSize, smallSize, thumbnailSize }; //Folder name within Blob storage for application image collection //var folderName = "applicationimages"; //" + imageId; //<-- Each image lives within a folder named after it's id: /applicationimages/[imageid]/[size].jpg //Image Format Settings var outputFormatString = "." + type; ISupportedImageFormat outputFormatProcessorProperty; // = new JpegFormat { Quality = 90 }; // <-- Format is automatically detected though can be changed. //ImageFormat outputFormatSystemrawingFormat; // = System.Drawing.Imaging.ImageFormat.Jpeg; if (type == "gif") { outputFormatProcessorProperty = new GifFormat { Quality = quality }; // <-- Format is automatically detected though can be changed. //outputFormatSystemrawingFormat = System.Drawing.Imaging.ImageFormat.Gif; } else if (type == "png") { outputFormatProcessorProperty = new PngFormat { Quality = quality }; // <-- Format is automatically detected though can be changed. //outputFormatSystemrawingFormat = System.Drawing.Imaging.ImageFormat.Png; } else { outputFormatProcessorProperty = new JpegFormat { Quality = quality }; // <-- Format is automatically detected though can be changed. //outputFormatSystemrawingFormat = System.Drawing.Imaging.ImageFormat.Jpeg; } /**/ //TO DO: IF ASPECT RATIO EXISTS THEN WE DETRIMINE THE SET SIZE (1 only) by method //Create instance of ApplicationImageDocumentModel to store image details into DocumentDB // var applicationImageDocumentModel = new ApplicationImageDocumentModel(); //applicationImageDocumentModel.Id = imageId; // applicationImageDocumentModel.FilePath = folderName; //<--Concatenates with each FileName for fil location //Note: We store all images in a single folder to make deletions more performant // applicationImageDocumentModel.FileNames = new ApplicationImageFileSizes(); //Get source file as MemoryStream from Blob storage and apply image processing tasks to each spcification using (MemoryStream sourceStream = Common.GetAssetFromIntermediaryStorage(sourceContainerName, sourceFileName)) { //var sourceBmp = new Bitmap(sourceStream); //<--Convert to BMP in order to run verifications //Verifiy Image Settings Align With Requirements /* * var verifySpecsResponse = Common.VerifyCommonImageSpecifications(sourceBmp, imageSpecs); * if (!verifySpecsResponse.isSuccess) * { * //return if fails * return verifySpecsResponse; * }*/ //Assign properties to the DocumentDB Document representation of this image //applicationImageDocumentModel.FileNames.Large = "large" + outputFormatString; //applicationImageDocumentModel.FileNames.Medium = "medium" + outputFormatString; //applicationImageDocumentModel.FileNames.Small = "small" + outputFormatString; //a/pplicationImageDocumentModel.FileNames.Thumbnail = "thumbnail" + outputFormatString; //Create 3 sizes (org, _sm & _xs) //List<Size> imageSizes = new List<Size>(); Dictionary <Size, string> imageSizes = new Dictionary <Size, string>(); imageSizes.Add(new Size(formatWidth, formatHeight), ""); //<-- ORG (no apennded file name) imageSizes.Add(new Size(formatWidth / 2, formatHeight / 2), "_sm"); //<-- SM (Half Size) imageSizes.Add(new Size(formatWidth / 4, formatHeight / 4), "_xs"); //<-- XS (Quarter Size) foreach (KeyValuePair <Size, string> entry in imageSizes) { Size processingSize = entry.Key; string appendedFileName = entry.Value; #region Image Processor & Storage //Final location for EACH image will be: http://[uri]/[containerName]/[imageId]_[size].[format] var filename = imageId + appendedFileName + outputFormatString; //<-- [imageid][_xx].xxx var fileNameFull = folderName + "/" + filename; //<-- /applicationimages/[imageid][_xx].xxx //Size processingSize = new Size(formatWidth, formatHeight); var resizeLayer = new ResizeLayer(processingSize) { ResizeMode = ResizeMode.Crop, AnchorPosition = AnchorPosition.Center }; using (MemoryStream outStream = new MemoryStream()) { using (ImageFactory imageFactory = new ImageFactory()) { // Load, resize, set the format and quality and save an image. // Applies all in order... sourceStream.Position = 0; //<-- Have to set position to 0 to makse sure imageFactory.Load starts from the begining. imageFactory.Load(sourceStream); if (imageCropCoordinates != null) { var cropLayer = new ImageProcessor.Imaging.CropLayer(imageCropCoordinates.Left, imageCropCoordinates.Top, imageCropCoordinates.Right, imageCropCoordinates.Bottom, CropMode.Pixels); //var cropRectangle = new Rectangle(imageCropCoordinates.Top, imageCropCoordinates.Left); imageFactory.Crop(cropLayer); //<-- Crop first imageFactory.Resize(resizeLayer); //<-- Then resize } else { imageFactory.Resize(resizeLayer);//<-- Resize } //Convert to proper format imageFactory.Format(outputFormatProcessorProperty); if (imageEnhancementInstructions != null) { //Basics --- if (imageEnhancementInstructions.Brightness != 0) { imageFactory.Brightness(imageEnhancementInstructions.Brightness); } if (imageEnhancementInstructions.Contrast != 0) { imageFactory.Contrast(imageEnhancementInstructions.Contrast); } if (imageEnhancementInstructions.Saturation != 0) { imageFactory.Saturation(imageEnhancementInstructions.Saturation); } // Sharpness --- if (imageEnhancementInstructions.Sharpen != 0) { imageFactory.GaussianSharpen(imageEnhancementInstructions.Sharpen); } //Filters ---- if (imageEnhancementInstructions.Sepia == true) { imageFactory.Filter(MatrixFilters.Sepia); } if (imageEnhancementInstructions.Polaroid == true) { imageFactory.Filter(MatrixFilters.Polaroid); } if (imageEnhancementInstructions.Greyscale == true) { imageFactory.Filter(MatrixFilters.GreyScale); } } imageFactory.Save(outStream); } //Store image size to BLOB STORAGE --------------------------------- #region BLOB STORAGE //CloudBlobClient blobClient = Sahara.Core.Settings.Azure.Storage.StorageConnections.AccountsStorage.CreateCloudBlobClient(); CloudBlobClient blobClient = Settings.Azure.Storage.GetStoragePartitionAccount(storagePartition).CreateCloudBlobClient(); //Create and set retry policy IRetryPolicy exponentialRetryPolicy = new ExponentialRetry(TimeSpan.FromMilliseconds(400), 6); blobClient.DefaultRequestOptions.RetryPolicy = exponentialRetryPolicy; //Creat/Connect to the Blob Container blobClient.GetContainerReference(accountId).CreateIfNotExists(BlobContainerPublicAccessType.Blob); //<-- Create and make public CloudBlobContainer blobContainer = blobClient.GetContainerReference(accountId); //Get reference to the picture blob or create if not exists. CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(fileNameFull); if (type == "gif") { blockBlob.Properties.ContentType = "image/gif"; } else if (type == "png") { blockBlob.Properties.ContentType = "image/png"; } else { blockBlob.Properties.ContentType = "image/jpg"; } //Save to storage //Convert final BMP to byteArray Byte[] finalByteArray; finalByteArray = outStream.ToArray(); blockBlob.UploadFromByteArray(finalByteArray, 0, finalByteArray.Length); #endregion } #endregion } }
//ExEnd:ApplyLicense public static string CleanFile(string filePath) { try { try { //Apply license... ApplyLicense(); } catch (Exception exp) { MessageBox.Show("In Licence: " + exp.Message); } try { //Recognize format of file... FormatBase format = FormatFactory.RecognizeFormat(filePath); if (format.Type.ToString().ToLower() == "doc" || format.Type.ToString().ToLower() == "docx") { // initialize DocFormat... DocFormat docFormat = format as DocFormat; if (docFormat != null) { // get document properties... DocMetadata properties = new DocMetadata(); properties = docFormat.DocumentProperties; //Remove custom properties... foreach (KeyValuePair<string, PropertyValue> keyValuePair in properties) { if (!properties.IsBuiltIn(keyValuePair.Key)) { properties.Remove(keyValuePair.Key); } } //Reset built-in properties... properties.Author = ""; properties.Category = ""; properties.Comments = ""; properties.Company = ""; properties.ContentStatus = ""; properties.HyperlinkBase = ""; properties.Keywords = ""; properties.Manager = ""; properties.Title = ""; //Update metadata if file... MetadataUtility.UpdateMetadata(filePath, properties); } return "1"; } else if (format.Type.ToString().ToLower() == "xls" || format.Type.ToString().ToLower() == "xlsx") { //Initialize XlsFormat... XlsFormat xlsFormat = format as XlsFormat; if (xlsFormat != null) { //Get document properties... XlsMetadata properties = xlsFormat.DocumentProperties; //Remove custom properties... foreach (KeyValuePair<string, PropertyValue> keyValuePair in properties) { if (!properties.IsBuiltIn(keyValuePair.Key)) { properties.Remove(keyValuePair.Key); } } //Reset built-in properties... properties.Author = ""; properties.Category = ""; properties.Comments = ""; properties.Company = ""; properties.HyperlinkBase = ""; properties.Keywords = ""; properties.Manager = ""; properties.Title = ""; properties.Subject = ""; //Update metadata in files... MetadataUtility.UpdateMetadata(filePath, properties); } return "1"; } else if (format.Type.ToString().ToLower() == "ppt" || format.Type.ToString().ToLower() == "pptx") { //Initialize PptFormat... PptFormat pptFormat = format as PptFormat; if (pptFormat != null) { //Get document properties... PptMetadata properties = pptFormat.DocumentProperties; //Remove custom properties foreach (KeyValuePair<string, PropertyValue> keyValuePair in properties) { if (!properties.IsBuiltIn(keyValuePair.Key)) { properties.Remove(keyValuePair.Key); } } //Reset built-in properties... properties.Author = ""; properties.Category = ""; properties.Comments = ""; properties.Company = ""; properties.Keywords = ""; properties.Manager = ""; properties.Title = ""; properties.Subject = ""; //Update metadata of file... MetadataUtility.UpdateMetadata(filePath, properties); } return "1"; } else if (format.Type.ToString().ToLower() == "pdf") { // initialize PdfFormat... PdfFormat pdfFormat = format as PdfFormat; if (pdfFormat != null) { // get document properties... PdfMetadata properties = pdfFormat.DocumentProperties; // Remove custom properties... foreach (KeyValuePair<string, PropertyValue> keyValuePair in properties) { if (!properties.IsBuiltIn(keyValuePair.Key)) { properties.Remove(keyValuePair.Key); } } //Reset built-in properties... properties.Author = ""; properties.CreatedDate = DateTime.MinValue; properties.Keywords = ""; properties.ModifiedDate = DateTime.MinValue; properties.Subject = ""; properties.TrappedFlag = false; properties.Title = ""; //Update metadata of file... MetadataUtility.UpdateMetadata(filePath, properties); } return "1"; } else if (format.Type.ToString().ToLower() == "jpeg" || format.Type.ToString().ToLower() == "jpg") { //Get EXIF data if exists ExifMetadata exifMetadata = (ExifMetadata)MetadataUtility.ExtractSpecificMetadata(filePath, MetadataType.EXIF); //Get XMP data if exists XmpMetadata xmpMetadata = (XmpMetadata)MetadataUtility.ExtractSpecificMetadata(filePath, MetadataType.XMP); if (exifMetadata != null) { //Remove exif info... ExifInfo exifInfo = exifMetadata.Data; if (exifInfo.GPSData != null) { // set altitude, latitude and longitude to null values exifInfo.GPSData.Altitude = null; exifInfo.GPSData.Latitude = null; exifInfo.GPSData.LatitudeRef = null; exifInfo.GPSData.Longitude = null; exifInfo.GPSData.LongitudeRef = null; } exifInfo.BodySerialNumber = ""; exifInfo.CameraOwnerName = ""; exifInfo.CFAPattern = new byte[] { 0 }; } else { exifMetadata = new ExifMetadata(); } try { //Remove XMP data... XmpPacketWrapper xmpPacket = xmpMetadata.XmpPacket; if (xmpPacket != null) { if (xmpPacket.ContainsPackage(Namespaces.DublinCore)) { // if not - add DublinCore schema xmpPacket.AddPackage(new DublinCorePackage()); DublinCorePackage dublinCorePackage = (DublinCorePackage)xmpPacket.GetPackage(Namespaces.DublinCore); dublinCorePackage.Clear(); xmpMetadata.XmpPacket = xmpPacket; } } } catch { } //Update Exif info... try { MetadataUtility.UpdateMetadata(filePath, exifMetadata); } catch { } //Update XMP data... try { MetadataUtility.UpdateMetadata(filePath, xmpMetadata); } catch { } //Remove custom metadata if any... MetadataUtility.CleanMetadata(filePath); return "1"; } else if (format.Type.ToString().ToLower() == "png") { //Get XMP data... XmpMetadata xmpMetadata = (XmpMetadata)MetadataUtility.ExtractSpecificMetadata(filePath, MetadataType.XMP); try { //Remove XMP metadata... XmpPacketWrapper xmpPacket = xmpMetadata.XmpPacket; if (xmpPacket != null) { if (xmpPacket.ContainsPackage(Namespaces.DublinCore)) { // if not - add DublinCore schema xmpPacket.AddPackage(new DublinCorePackage()); DublinCorePackage dublinCorePackage = (DublinCorePackage)xmpPacket.GetPackage(Namespaces.DublinCore); dublinCorePackage.Clear(); xmpMetadata.XmpPacket = xmpPacket; //Update XMP metadata in file... MetadataUtility.UpdateMetadata(filePath, xmpMetadata); //Clean custom metadata if any... MetadataUtility.CleanMetadata(filePath); } } } catch { } return "1"; } else if (format.Type.ToString().ToLower() == "gif") { //Initialie GifFormat... GifFormat gifFormat = new GifFormat(filePath); //Check if Xmp supported... if (gifFormat.IsSupportedXmp) { //Get XMP data... XmpMetadata xmpMetadata = (XmpMetadata)MetadataUtility.ExtractSpecificMetadata(filePath, MetadataType.XMP); try { XmpPacketWrapper xmpPacket = xmpMetadata.XmpPacket; if (xmpPacket != null) { if (xmpPacket.ContainsPackage(Namespaces.DublinCore)) { // if not - add DublinCore schema xmpPacket.AddPackage(new DublinCorePackage()); DublinCorePackage dublinCorePackage = (DublinCorePackage)xmpPacket.GetPackage(Namespaces.DublinCore); dublinCorePackage.Clear(); xmpMetadata.XmpPacket = xmpPacket; //Update Xmp data in file... MetadataUtility.UpdateMetadata(filePath, xmpMetadata); //Clean custom metadata if any... MetadataUtility.CleanMetadata(filePath); } } } catch { } } return "1"; } else { return "Format not supported."; } } catch( Exception exp) { MessageBox.Show("Exception: " + exp.Message); return exp.Message; } } catch (Exception exp) { return exp.Message; } }
public HttpResponseMessage Get(string file) { try { File.Copy(Utils._storagePath + "\\" + file, Utils._storagePath + "\\Cleaned_" + file, true); FileStream original = File.Open(Utils._storagePath + "\\Cleaned_" + file, FileMode.Open, FileAccess.ReadWrite); FileFormatChecker fileFormatChecker = new FileFormatChecker(original); DocumentType documentType = fileFormatChecker.GetDocumentType(); if (fileFormatChecker.VerifyFormat(documentType)) { switch (documentType) { case DocumentType.Doc: DocFormat docFormat = new DocFormat(original); docFormat.CleanMetadata(); docFormat.ClearBuiltInProperties(); docFormat.ClearComments(); docFormat.ClearCustomProperties(); docFormat.RemoveHiddenData(new DocInspectionOptions(DocInspectorOptionsEnum.All)); docFormat.Save(Utils._storagePath + "\\Cleaned_" + file); break; case DocumentType.Xls: XlsFormat xlsFormat = new XlsFormat(original); xlsFormat.CleanMetadata(); xlsFormat.ClearBuiltInProperties(); xlsFormat.ClearContentTypeProperties(); xlsFormat.ClearCustomProperties(); xlsFormat.RemoveHiddenData(new XlsInspectionOptions(XlsInspectorOptionsEnum.All)); xlsFormat.Save(Utils._storagePath + "\\Cleaned_" + file); break; case DocumentType.Pdf: PdfFormat pdfFormat = new PdfFormat(original); pdfFormat.CleanMetadata(); pdfFormat.ClearBuiltInProperties(); pdfFormat.ClearCustomProperties(); pdfFormat.RemoveHiddenData(new PdfInspectionOptions(PdfInspectorOptionsEnum.All)); pdfFormat.RemoveXmpData(); pdfFormat.Save(Utils._storagePath + "\\Cleaned_" + file); break; case DocumentType.Png: PngFormat pngFormat = new PngFormat(original); pngFormat.CleanMetadata(); pngFormat.RemoveXmpData(); pngFormat.Save(Utils._storagePath + "\\Cleaned_" + file); break; case DocumentType.Jpeg: JpegFormat jpegFormat = new JpegFormat(original); jpegFormat.CleanMetadata(); jpegFormat.RemoveExifInfo(); jpegFormat.RemoveGpsLocation(); jpegFormat.RemoveIptc(); jpegFormat.RemovePhotoshopData(); jpegFormat.RemoveXmpData(); jpegFormat.Save(original); break; case DocumentType.Bmp: BmpFormat bmpFormat = new BmpFormat(original); bmpFormat.CleanMetadata(); bmpFormat.Save(Utils._storagePath + "\\Cleaned_" + file); break; case DocumentType.Gif: GifFormat gifFormat = new GifFormat(original); gifFormat.CleanMetadata(); gifFormat.RemoveXmpData(); gifFormat.Save(Utils._storagePath + "\\Cleaned_" + file); break; case DocumentType.Msg: OutlookMessage outlookMessage = new OutlookMessage(original); outlookMessage.CleanMetadata(); outlookMessage.RemoveAttachments(); outlookMessage.Save(Utils._storagePath + "\\Cleaned_" + file); break; case DocumentType.Eml: EmlFormat emlFormat = new EmlFormat(original); emlFormat.CleanMetadata(); emlFormat.RemoveAttachments(); emlFormat.Save(Utils._storagePath + "\\Cleaned_" + file); break; case DocumentType.Dwg: DwgFormat dwgFormat = new DwgFormat(original); dwgFormat.CleanMetadata(); dwgFormat.Save(Utils._storagePath + "\\Cleaned_" + file); break; case DocumentType.Dxf: DxfFormat dxfFormat = new DxfFormat(original); dxfFormat.CleanMetadata(); dxfFormat.Save(Utils._storagePath + "\\Cleaned_" + file); break; default: DocFormat defaultDocFormat = new DocFormat(original); defaultDocFormat.CleanMetadata(); defaultDocFormat.ClearBuiltInProperties(); defaultDocFormat.ClearComments(); defaultDocFormat.ClearCustomProperties(); defaultDocFormat.RemoveHiddenData(new DocInspectionOptions(DocInspectorOptionsEnum.All)); defaultDocFormat.Save(Utils._storagePath + "\\Cleaned_" + file); break; } } else { throw new Exception("File format not supported."); } using (var ms = new MemoryStream()) { original = File.OpenRead(Utils._storagePath + "\\Cleaned_" + file); original.CopyTo(ms); var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(ms.ToArray()) }; result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment") { FileName = "Cleaned_" + file }; result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); original.Close(); File.Delete(Utils._storagePath + "\\Cleaned_" + file); return(result); } } catch (Exception exc) { throw exc; } }
/// <summary> /// Updates thumbnails in XMP data of Gif file and creates output file /// </summary> public static void UpdateThumbnailInXMPData() { try { //ExStart:UpdateThumbnailXmpPropertiesGifImage string path = Common.MapSourceFilePath(filePath); // initialize GifFormat GifFormat gifFormat = new GifFormat(Common.MapSourceFilePath(filePath)); // get image base64 string string base64String; using (Image image = Image.FromFile(path)) { using (MemoryStream m = new MemoryStream()) { image.Save(m, image.RawFormat); byte[] imageBytes = m.ToArray(); // Convert byte[] to Base64 String base64String = Convert.ToBase64String(imageBytes); } } // create image thumbnail Thumbnail thumbnail = new Thumbnail { ImageBase64 = base64String }; // initialize array and add thumbnail Thumbnail[] thumbnails = new Thumbnail[1]; thumbnails[0] = thumbnail; // update thumbnails property in XMP Basic schema gifFormat.XmpValues.Schemes.XmpBasic.Thumbnails = thumbnails; // commit changes gifFormat.Save(Common.MapDestinationFilePath(filePath)); //ExEnd:UpdateThumbnailXmpPropertiesGifImage Console.WriteLine("File saved in destination folder."); } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Updates Basic Job XMP data of Gif file and creates output file /// </summary> public static void UpdateBasicJobXMPProperties() { try { //ExStart:UpdateBasicJobTicketXmpPropertiesGifImage // initialize GifFormat GifFormat gifFormat = new GifFormat(Common.MapSourceFilePath(filePath)); // get xmp data var xmp = gifFormat.GetXmpData(); BasicJobTicketPackage package = null; // looking for the BasicJob schema if xmp data is presented if (xmp != null) { package = xmp.GetPackage(Namespaces.BasicJob) as BasicJobTicketPackage; } else { xmp = new XmpPacketWrapper(); } if (package == null) { // create package if not exist package = new BasicJobTicketPackage(); // and add it to xmp data xmp.AddPackage(package); } // create array of jobs Job[] jobs = new Job[1]; jobs[0] = new Job() { Id = "1", Name = "test job" }; // update schema package.SetJobs(jobs); // update xmp data gifFormat.SetXmpData(xmp); // commit changes gifFormat.Save(Common.MapDestinationFilePath(filePath)); //ExEnd:UpdateBasicJobTicketXmpPropertiesGifImage Console.WriteLine("File saved in destination folder."); } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Updates CameraRaw XMP data of Gif file and creates output file /// </summary> public static void UpdateCameraRawXMPProperties() { try { //ExStart:UpdateCameraRawXmpPropertiesGifImage // initialize GifFormat GifFormat GifFormat = new GifFormat(Common.MapSourceFilePath(filePath)); // get access to CameraRaw schema var package = GifFormat.XmpValues.Schemes.CameraRaw; // update properties package.AutoBrightness = true; package.AutoContrast = true; package.CropUnits = CropUnits.Pixels; // update white balance package.SetWhiteBalance(WhiteBalance.Auto); // commit changes GifFormat.Save(Common.MapDestinationFilePath(filePath)); //ExEnd:UpdateCameraRawXmpPropertiesGifImage Console.WriteLine("File saved in destination folder."); } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Updates PagedText XMP data of Gif file and creates output file /// </summary> public static void UpdatePagedTextXMPProperties() { try { //ExStart:UpdatePagedTextXmpPropertiesGifImage // initialize GifFormat GifFormat GifFormat = new GifFormat(Common.MapSourceFilePath(filePath)); // get access to PagedText schema var package = GifFormat.XmpValues.Schemes.PagedText; // update MaxPageSize package.MaxPageSize = new Dimensions(600, 800); // update number of pages package.NumberOfPages = 10; // update plate names package.PlateNames = new string[] { "1", "2", "3" }; // commit changes GifFormat.Save(Common.MapDestinationFilePath(filePath)); //ExEnd:UpdatePagedTextXmpPropertiesGifImage Console.WriteLine("File saved in destination folder."); } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Updates XMP values of Gif file and creates output file /// </summary> public static void UpdateXMPValues() { try { //ExStart:UpdateXmpValuesGifImage // initialize GifFormat GifFormat GifFormat = new GifFormat(Common.MapSourceFilePath(filePath)); const string dcFormat = "test format"; string[] dcContributors = { "test contributor" }; const string dcCoverage = "test coverage"; const string phCity = "NY"; const string phCountry = "USA"; const string xmpCreator = "GroupDocs.Metadata"; GifFormat.XmpValues.Schemes.DublinCore.Format = dcFormat; GifFormat.XmpValues.Schemes.DublinCore.Contributors = dcContributors; GifFormat.XmpValues.Schemes.DublinCore.Coverage = dcCoverage; GifFormat.XmpValues.Schemes.Photoshop.City = phCity; GifFormat.XmpValues.Schemes.Photoshop.Country = phCountry; GifFormat.XmpValues.Schemes.XmpBasic.CreatorTool = xmpCreator; // commit changes GifFormat.Save(Common.MapDestinationFilePath(filePath)); //ExEnd:UpdateXmpValuesGifImage Console.WriteLine("File saved in destination folder."); } catch (Exception exp) { Console.WriteLine(exp.Message); } }
public JsonResult <List <PropertyItem> > Get(string file) { try { FileStream original = File.Open(Utils._storagePath + "\\" + file, FileMode.OpenOrCreate); FileFormatChecker fileFormatChecker = new FileFormatChecker(original); DocumentType documentType = fileFormatChecker.GetDocumentType(); List <PropertyItem> values = new List <PropertyItem>(); if (fileFormatChecker.VerifyFormat(documentType)) { switch (documentType) { case DocumentType.Doc: DocFormat docFormat = new DocFormat(original); values = AppendMetadata(docFormat.GetMetadata(), values); break; case DocumentType.Xls: XlsFormat xlsFormat = new XlsFormat(original); values = AppendMetadata(xlsFormat.GetMetadata(), values); break; case DocumentType.Pdf: PdfFormat pdfFormat = new PdfFormat(original); values = AppendMetadata(pdfFormat.GetMetadata(), values); values = AppendXMPData(pdfFormat.GetXmpData(), values); break; case DocumentType.Png: PngFormat pngFormat = new PngFormat(original); values = AppendMetadata(pngFormat.GetMetadata(), values); values = AppendXMPData(pngFormat.GetXmpData(), values); break; case DocumentType.Jpeg: JpegFormat jpegFormat = new JpegFormat(original); values = AppendMetadata(jpegFormat.GetMetadata(), values); values = AppendXMPData(jpegFormat.GetXmpData(), values); break; case DocumentType.Gif: GifFormat gifFormat = new GifFormat(original); values = AppendMetadata(gifFormat.GetMetadata(), values); values = AppendXMPData(gifFormat.GetXmpData(), values); break; case DocumentType.Bmp: BmpFormat bmpFormat = new BmpFormat(original); values = AppendMetadata(bmpFormat.GetMetadata(), values); break; case DocumentType.Msg: OutlookMessage outlookMessage = new OutlookMessage(original); values = AppendMetadata(outlookMessage.GetMsgInfo(), values); break; case DocumentType.Eml: EmlFormat emlFormat = new EmlFormat(original); values = AppendMetadata(emlFormat.GetEmlInfo(), values); break; case DocumentType.Dwg: DwgFormat dwgFormat = new DwgFormat(original); values = AppendMetadata(dwgFormat.GetMetadata(), values); break; case DocumentType.Dxf: DxfFormat dxfFormat = new DxfFormat(original); values = AppendMetadata(dxfFormat.GetMetadata(), values); break; default: DocFormat defaultDocFormat = new DocFormat(original); values = AppendMetadata(defaultDocFormat.GetMetadata(), values); break; } return(Json(values)); } else { throw new Exception("File format not supported."); } } catch (Exception exc) { throw exc; } }