public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AI(); //ExStart:AIToGIF string[] sourcesFiles = new string[] { @"34992OStroke", @"rect2_color", }; for (int i = 0; i < sourcesFiles.Length; i++) { string name = sourcesFiles[i]; string sourceFileName = dataDir + name + ".ai"; string outFileName = dataDir + name + ".gif"; using (AiImage image = (AiImage)Image.Load(sourceFileName)) { ImageOptionsBase options = new GifOptions() { DoPaletteCorrection = false }; image.Save(outFileName, options); } } //ExEnd:AIToGIF }
static void CreateTempDirectory(this GifOptions options) { if (!(Directory.Exists(options.Temp))) { Directory.CreateDirectory(options.Temp); } }
static void DeleteTempDirectory(this GifOptions options) { if (Directory.Exists(options.Temp)) { Directory.Delete(options.Temp, true); } }
static void CompleteGifOptions(this GifOptions options, Upload video, Upload gif, IHostingEnvironment env) { options.Exec = env.GetExecPath(); options.Temp = env.GetTempPath(); options.Origin = video.Path; options.Destination = gif.Path; }
public static async Task <ConsoleOutput> ConvertToGif(this GifOptions model) { var script = await model.GenerateGifScript(); var output = await script.ExecuteCommand(); if (!output.HasError) { output.Result = $"{model.Destination.Split('/').Last()} successfully created"; } return(output); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:ControllCacheReallocation // The path to the documents directory. // string dataDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); // By default the cache folder is set to the local temp directory. You can specify a different cache folder from the default this way: Cache.CacheFolder = dataDir; // Set cache on disk. Cache.CacheType = CacheType.CacheOnDiskOnly; // The default cache max value is 0, which means that there is no upper limit Cache.MaxDiskSpaceForCache = 1073741824; // 1 gigabyte Cache.MaxMemoryForCache = 1073741824; // 1 gigabyte // We do not recommend that you change the following property because it may greatly affect performance Cache.ExactReallocateOnly = false; // At any time you can check how many bytes are currently allocated for the cache in memory or on disk By examining the following properties long l1 = Cache.AllocatedDiskBytesCount; long l2 = Cache.AllocatedMemoryBytesCount; GifOptions options = new GifOptions(); options.Palette = new ColorPalette(new[] { Color.Red, Color.Blue, Color.Black, Color.White }); options.Source = new StreamSource(new MemoryStream(), true); using (RasterImage image = (RasterImage)Image.Create(options, 100, 100)) { Color[] pixels = new Color[10000]; for (int i = 0; i < pixels.Length; i++) { pixels[i] = Color.White; } image.SavePixels(image.Bounds, pixels); // After executing the code above 40000 bytes are allocated to disk. long diskBytes = Cache.AllocatedDiskBytesCount; long memoryBytes = Cache.AllocatedMemoryBytesCount; } // The allocation properties may be used to check whether all Aspose.Imaging objects were properly disposed. If you've forgotten to call dispose on an object the cache values will not be 0. l1 = Cache.AllocatedDiskBytesCount; l2 = Cache.AllocatedMemoryBytesCount; //ExEnd:ControllCacheReallocation }
public static void Run() { // ExStart:ImplementationOfLossyGIFCompressor // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Sets the maximum allowed pixel difference. If greater than zero, lossy compression will be used. // Recommended value for optimal lossy compression is 80. 30 is very light compression, 200 is heavy. GifOptions gifExport = new GifOptions(); gifExport.MaxDiff = 80; using (Image image = Image.Load("anim_orig.gif")) { image.Save("anim_lossy-80.gif", gifExport); } // ExEnd:ImplementationOfLossyGIFCompressor }
public static async Task <Command> GenerateGifScript(this GifOptions model) { var script = await(".Scripts.Create-Gif.ps1").GetTextFromEmbeddedResource(); Command createGif = new Command(script, true); createGif.Parameters.Add("exec", model.Exec); createGif.Parameters.Add("origin", model.Origin); createGif.Parameters.Add("destination", model.Destination); createGif.Parameters.Add("temp", model.Temp); createGif.Parameters.Add("fps", model.Fps); createGif.Parameters.Add("scale", model.Scale); createGif.Parameters.Add("flags", model.Flags); createGif.Parameters.Add("log", model.Log); return(createGif); }
public static void Run() { // ExStart:ControllCacheReallocation // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Cache(); // By default the cache folder is set to the local temp directory. You can specify a different cache folder from the default this way: Cache.CacheFolder = dataDir; // Auto mode is flexible and efficient Cache.CacheType = CacheType.Auto; // The default cache max value is 0, which means that there is no upper limit Cache.MaxDiskSpaceForCache = 1073741824; // 1 gigabyte Cache.MaxMemoryForCache = 1073741824; // 1 gigabyte // We do not recommend that you change the following property because it may greatly affect performance Cache.ExactReallocateOnly = false; // At any time you can check how many bytes are currently allocated for the cache in memory or on disk By examining the following properties long l1 = Cache.AllocatedDiskBytesCount; long l2 = Cache.AllocatedMemoryBytesCount; GifOptions options = new GifOptions(); options.Palette = new ColorPalette(new[] { Color.Red, Color.Blue, Color.Black, Color.White }); options.Source = new StreamSource(new MemoryStream(), true); using (RasterImage image = (RasterImage)Image.Create(options, 100, 100)) { Color[] pixels = new Color[10000]; for (int i = 0; i < pixels.Length; i++) { pixels[i] = Color.White; } image.SavePixels(image.Bounds, pixels); // After executing the code above 40000 bytes are allocated to memory. long diskBytes = Cache.AllocatedDiskBytesCount; long memoryBytes = Cache.AllocatedMemoryBytesCount; } // The allocation properties may be used to check whether all Aspose.Imaging objects were properly disposed. If you've forgotten to call dispose on an object the cache values will not be 0. l1 = Cache.AllocatedDiskBytesCount; l2 = Cache.AllocatedMemoryBytesCount; // ExEnd:ControllCacheReallocation }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:PSDToRasterImageFormats String srcPath = dataDir + @"sample.psd"; string destName = dataDir + @"export"; // Load an existing PSD image as Image using (Image image = Image.Load(srcPath)) { // Create an instance of PngOptions class PngOptions pngOptions = new PngOptions(); // Create an instance of BmpOptions class BmpOptions bmpOptions = new BmpOptions(); // Create an instance of TiffOptions class TiffOptions tiffOptions = new TiffOptions(FileFormats.Tiff.Enums.TiffExpectedFormat.Default); // Create an instance of GifOptions class GifOptions gifOptions = new GifOptions(); // Create an instance of JpegOptions class JpegOptions jpegOptions = new JpegOptions(); // Create an instance of Jpeg2000Options class Jpeg2000Options jpeg2000Options = new Jpeg2000Options(); // Call the save method, provide output path and export options to convert PSD file to various raster file formats. image.Save(destName + ".png", pngOptions); image.Save(destName + ".bmp", bmpOptions); image.Save(destName + ".tiff", tiffOptions); image.Save(destName + ".gif", gifOptions); image.Save(destName + ".jpeg", jpegOptions); image.Save(destName + ".jp2", jpeg2000Options); } //ExEnd:PSDToRasterImageFormats }
public static async Task <ConsoleOutput> ConvertToGif(this GifOptions model) { try { InitialSessionState iss = InitialSessionState.CreateDefault(); // iss.ExecutionPolicy = Microsoft.PowerShell.ExecutionPolicy.Unrestricted; using (Runspace rs = RunspaceFactory.CreateRunspace(iss)) { rs.Open(); var script = await(".Scripts.Create-Gif.ps1").GetTextFromEmbeddedResource(); Command createGif = new Command(script, true); createGif.Parameters.Add("exec", model.exec); createGif.Parameters.Add("origin", model.origin); createGif.Parameters.Add("destination", model.destination); createGif.Parameters.Add("fps", model.fps); createGif.Parameters.Add("scale", model.scale); createGif.Parameters.Add("flags", model.flags); createGif.Parameters.Add("log", model.log); using (PowerShell ps = PowerShell.Create()) { ps.Runspace = rs; ps.Commands.AddCommand(createGif); ps.Invoke(); var output = await ps.GetPowershellOutput(); if (!output.hasError) { output.result = $"{model.destination} successfully created"; } return(output); } } } catch (Exception ex) { throw new Exception(ex.GetExceptionMessageChain()); } }
///<Summary> /// ConvertCadToImages method to convert cad to images ///</Summary> public Response ConvertCadToImages(string fileName, string folderName, string outputType) { if (outputType.Equals("bmp") || outputType.Equals("jpg") || outputType.Equals("png") || outputType.Equals("gif") || outputType.Equals("svg")) { ImageOptionsBase imageOptionsBase = new BmpOptions(); if (outputType.Equals("jpg")) { imageOptionsBase = new JpegOptions(); } else if (outputType.Equals("png")) { imageOptionsBase = new PngOptions(); } else if (outputType.Equals("gif")) { imageOptionsBase = new GifOptions(); } else if (outputType.Equals("svg")) { imageOptionsBase = new SvgOptions(); } return(ProcessTask(fileName, folderName, "." + outputType, false, false, delegate(string inFilePath, string outPath, string zipOutFolder) { using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(inFilePath)) { image.Save(outPath, imageOptionsBase); } })); } return(new Response { FileName = null, Status = "Output type not found", StatusCode = 500 }); }
///<Summary> /// ConvertPSDToImageFiles method to convert psd to image ///</Summary> public Response ConvertPSDToImageFiles(string fileName, string folderName, string outputType) { if (outputType.Equals("bmp") || outputType.Equals("jpg") || outputType.Equals("png")) { ImageOptionsBase optionsBase = new BmpOptions(); if (outputType.Equals("jpg")) { optionsBase = new JpegOptions(); } else if (outputType.Equals("png")) { optionsBase = new PngOptions(); } else if (outputType.Equals("gif")) { optionsBase = new GifOptions(); } return(ProcessTask(fileName, folderName, "." + outputType, true, false, delegate(string inFilePath, string outPath, string zipOutFolder) { string fileExtension = Path.GetExtension(inFilePath).ToLower(); using (Image image = Image.Load(inFilePath)) { image.Save(outPath, optionsBase); } })); } return(new Response { FileName = null, Status = "Output type not found", StatusCode = 500 }); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:ImplementLossyGIFCompressor String sourceFile = dataDir + @"sample.psd"; string destName = dataDir + @"anim_lossy-200.gif"; GifOptions gifExport = new GifOptions(); // Load an existing image into an instance of RasterImage class using (var image = Image.Load(sourceFile)) { gifExport.MaxDiff = 80; image.Save("anim_lossy-80.gif", gifExport); gifExport.MaxDiff = 200; image.Save(destName, gifExport); } //ExEnd:ImplementLossyGIFCompressor }
///<Summary> /// ConvertImageFormat method to convert image to different image formats ///</Summary> public Response ConvertImageFormat(string fileName, string folderName, string outputType) { if (outputType.Equals("gif") || outputType.Equals("bmp") || outputType.Equals("jpg") || outputType.Equals("png") || outputType.Equals("psd") || outputType.Equals("emf") || outputType.Equals("svg") || outputType.Equals("wmf")) { ImageOptionsBase optionsBase = new BmpOptions(); if (outputType.Equals("jpg")) { optionsBase = new JpegOptions(); } else if (outputType.Equals("png")) { optionsBase = new PngOptions(); } else if (outputType.Equals("gif")) { optionsBase = new GifOptions(); } else if (outputType.Equals("psd")) { optionsBase = new PsdOptions(); } else if (outputType.Equals("emf")) { optionsBase = new EmfOptions(); } else if (outputType.Equals("svg")) { optionsBase = new SvgOptions(); } else if (outputType.Equals("wmf")) { optionsBase = new WmfOptions(); } return(ProcessTask(fileName, folderName, "." + outputType, true, true, delegate(string inFilePath, string outPath, string zipOutFolder) { string fileExtension = Path.GetExtension(inFilePath).ToLower(); if ((fileExtension == ".tif") || (fileExtension == ".tiff")) { string outfileName = Path.GetFileNameWithoutExtension(fileName) + "_{0}"; using (TiffImage multiImage = (TiffImage)Image.Load(inFilePath)) { if (multiImage.Frames.Length > 1) { int frameCounter = 0; // Iterate over the TiffFrames in TiffImage foreach (TiffFrame tiffFrame in multiImage.Frames) { multiImage.ActiveFrame = tiffFrame; // Load Pixels of TiffFrame into an array of Colors Color[] pixels = multiImage.LoadPixels(tiffFrame.Bounds); // Create an instance of JpegOptions // Set the Source of JpegOptions as FileCreateSource by specifying the location where output will be saved // Last boolean parameter denotes isTemporal outPath = zipOutFolder + "/" + outfileName; optionsBase.Source = new FileCreateSource(string.Format(outPath, frameCounter + 1) + "." + outputType, false); // Create a new RasterImage of Jpeg type using (var jpgImage = (RasterImage)Image.Create(optionsBase, tiffFrame.Width, tiffFrame.Height)) { // Save the JpegImage with pixels from TiffFrame jpgImage.SavePixels(tiffFrame.Bounds, pixels); // Resize the Jpeg Image jpgImage.Resize(100, 100, ResizeType.NearestNeighbourResample); // Save the results on disk jpgImage.Save(); } frameCounter++; } } else { multiImage.Save(outPath, optionsBase); } } } else { using (Image image = Image.Load(inFilePath)) { image.Save(outPath, optionsBase); } } })); } return(new Response { FileName = null, Status = "Output type not found", StatusCode = 500 }); }