// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseStatusCodePages("text/plain", "{0}"); } app.UseStaticFiles(); app.UseRouting(); app.UseResponseCaching(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); Directory.CreateDirectory(ImageGallery.Configuration.Get.TempDir); MagickNET.SetTempDirectory(ImageGallery.Configuration.Get.TempDir); MagickNET.SetNativeLibraryDirectory(ImageGallery.Configuration.Get.TempDir); FFmpeg.SetExecutablesPath(Path.Combine(env.ContentRootPath, "ffmpeg")); }
public void ShouldThrowExceptionWhenPathIsNull() { Assert.Throws <ArgumentNullException>("path", () => { MagickNET.SetTempDirectory(null); }); }
public void SetTempDirectory_PathIsNull_ThrowsException() { ExceptionAssert.Throws <ArgumentNullException>(delegate() { MagickNET.SetTempDirectory(null); }); }
public void SetTempDirectory_PathIsNull_ThrowsException() { ExceptionAssert.ThrowsArgumentNullException("path", () => { MagickNET.SetTempDirectory(null); }); }
public void ShouldThrowExceptionWhenPathIsInvalid() { Assert.Throws <ArgumentException>("path", () => { MagickNET.SetTempDirectory("Invalid"); }); }
public void MakeList(List <string> images, string tempFolder, int dpi, uint MemoryMBLimit = 500, Action <int> updateIndex = null) { if (images == null) { return; } ImageMagick.ResourceLimits.Memory = MemoryMBLimit * 1024 * 1024; // When reading PDF : // MagickNET.SetGhostscriptDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); // https://github.com/dlemstra/Magick.NET/tree/master/Documentation#ghostscript // get files from extracting installer (64 and 32 bit) from official ghostscript site MagickNET.SetTempDirectory(tempFolder); collection = new MagickImageCollection(); int counter = 0; foreach (string imagepath in images) { ImageMagick.MagickImage img = new MagickImage(imagepath); img.Density = new Density(dpi); collection.Add(img); updateIndex?.Invoke(counter); counter = counter + 1; } }
public void SetTempDirectory_PathIsInvalid_ThrowsException() { ExceptionAssert.ThrowsArgumentException("path", () => { MagickNET.SetTempDirectory("Invalid"); }); }
public Program() { CreatePIDFile(); Console.Title = Constants.ApplicationName; ConsoleColor originalColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"==================================="); Console.WriteLine($"======= {Constants.ApplicationName} v{Constants.ApplicationVersion} ======="); Console.WriteLine("=== https://github.com/Xathz ==="); Console.WriteLine($"==================================="); Console.ForegroundColor = originalColor; Console.WriteLine(); Directory.CreateDirectory(Constants.WorkingDirectory); Directory.CreateDirectory(Constants.LogDirectory); Directory.CreateDirectory(Constants.RuntimesDirectory); Directory.CreateDirectory(Constants.TemporaryDirectory); Directory.CreateDirectory(Constants.MagickNETDirectory); Directory.CreateDirectory(Constants.ContentDirectory); LoggingManager.Initialize(); SettingsManager.Load(); DatabaseManager.Load(); StatisticsManager.Load(); MagickNET.SetTempDirectory(Constants.MagickNETDirectory); // Increase humanizer's precision Configurator.DateTimeHumanizeStrategy = new PrecisionDateTimeHumanizeStrategy(precision: .95); Configurator.DateTimeOffsetHumanizeStrategy = new PrecisionDateTimeOffsetHumanizeStrategy(precision: .95); }
public void SetTempDirectory_PathIsInvalid_ThrowsException() { ExceptionAssert.Throws <ArgumentException>(delegate() { MagickNET.SetTempDirectory("Invalid"); }); }
public Form1() { InitializeComponent(); this.magickCacheDirectory = Path.Combine(Directory.GetCurrentDirectory(), "MagickTemp"); this.testFile = Path.Combine(Directory.GetCurrentDirectory(), "TestFile.tif"); Directory.CreateDirectory(magickCacheDirectory); magickCacheDirectoryWatcher.Path = magickCacheDirectory; MagickNET.SetTempDirectory(magickCacheDirectory); }
static void Main(string[] args) { MagickNET.SetTempDirectory(Environment.CurrentDirectory); try { MainMain(args).GetAwaiter().GetResult(); } catch (Exception e) { Console.WriteLine(e.ToString()); } }
public TitanicIMArray(ITitanicArrayConfig <T> config) { this.config = config; TSize = GetSizeInBytes(config.DataSerializer); pixelsPerItem = IntCeil(TSize, bytesPerPixel); long maxPixels = config.Capacity * pixelsPerItem; FindDimensions(maxPixels, out Width, out Height); MagickNET.SetTempDirectory(Path.GetDirectoryName(config.BackingStoreFileName)); im = new MagickImage(MagickColor.FromRgba(0, 0, 0, 0), Width, Height); pixels = im.GetPixels(); }
public void Test_SetTempDirectory() { ExceptionAssert.Throws <ArgumentNullException>(delegate() { MagickNET.SetTempDirectory(null); }); ExceptionAssert.Throws <ArgumentException>(delegate() { MagickNET.SetTempDirectory("Invalid"); }); MagickNET.SetTempDirectory(Path.GetTempPath()); }
public ThumbnailGenerator() { string temporaryImagesFilePath = @"f:\data\launchpad\images\temp"; MagickNET.SetTempDirectory(temporaryImagesFilePath); string policyMap = @" <policymap> <policy domain=""resource"" name=""memory"" value=""3GiB""/> <policy domain=""resource"" name=""map"" value=""4GiB""/> <policy domain=""resource"" name=""time"" value=""unlimited""/> </policymap> "; Configuration = new ImageMagickConfiguration(policyMap, temporaryImagesFilePath); }
public void JpgsToGif() { MagickNET.SetTempDirectory(_tempFilesDirectory); using (MagickImageCollection mic = new MagickImageCollection()) { foreach (var image in Jpgs) { MagickImage mi = new MagickImage(image); mi.Resize(Width, Height); mi.AnimationDelay = 100 / Fps; mic.Add(mi); } mic.Write(GifFileName); } }
static void Main(string[] args) { var args_parsed = Parser.Default.ParseArguments <ColorOptions, DuplexOptions>(args) .WithParsed <ColorOptions>((options) => { ImageMagick.ResourceLimits.Memory = (ulong)options.LimitMB * (ulong)Math.Pow(1024, 2); // 2=MB, 3=GB ... if (options.OderByName ?? true) { GlobalOrderFunc = (si) => si.Name; } //ImageMagick.ResourceLimits.Thread = (ulong)options.workers; MagickNET.SetTempDirectory(System.IO.Path.GetTempPath()); Color(options); if (options.Pause) { Pause(); } }) .WithParsed <DuplexOptions>((options) => { ImageMagick.ResourceLimits.Memory = (ulong)options.LimitMB * (ulong)Math.Pow(1024, 2); // 2=MB, 3=GB ... if (options.OderByName ?? true) { GlobalOrderFunc = (si) => si.Name; } Duplex(options); if (options.Pause) { Pause(); } }) .WithNotParsed(errors => { log.e("Error parsing inputs"); foreach (var e in errors) { log.e(e); } }); }
static void Main(string[] args) { MagickNET.SetTempDirectory(Path.Combine("temp")); string[] fileEntries = Directory.GetFiles(Path.Combine("images")); foreach (string file in fileEntries) { try { ProcessImage(file); } catch (Exception) { Console.WriteLine("Failed:" + file); } } }
public void New_Thumbnail_Generator_ConfigurationConstructor_Configuration_ShouldNot_Be_Null() { // Create the default ImageMagick configuration, which also initializes the underlying ImageMagick utility string temporaryImagesFilePath = @"f:\data\launchpad\images\temp"; MagickNET.SetTempDirectory(temporaryImagesFilePath); string policyMap = @" <policymap> <policy domain=""resource"" name=""memory"" value=""3GiB""/> <policy domain=""resource"" name=""map"" value=""4GiB""/> <policy domain=""resource"" name=""time"" value=""unlimited""/> </policymap> "; ImageMagickConfiguration config = new ImageMagickConfiguration(policyMap, temporaryImagesFilePath); ThumbnailGenerator generator = new ThumbnailGenerator(config); generator.Configuration.Should().NotBeNull(); }
static void Main(string[] args) { MagickNET.SetTempDirectory(Environment.CurrentDirectory); #if DEBUG Debug.Listeners.Add(new ConsoleTraceListener()); #endif try { MainMain(args); } catch (Exception e) { #if DEBUG string err = e.ToString(); #else string err = e.Message; #endif Logger.PrintError(err); } }
///<summary> /// Start-up Form Data /// </summary> /// <info> /// This is all just setting up the setting for the application, setting defult values and declaring a place for /// Temp data to go to make it easyer for the users to see /// </info> private void ComprestionTool_Load(object sender, EventArgs e) { lstFormats.SetSelected(0, true); lstcolorSpace.SetSelected(0, true); MagickNET.SetTempDirectory(String.Format(AppDomain.CurrentDomain.BaseDirectory + "Temp")); MessageBox.Show(" Welcome to Compress My Image " + "\n" + "This software was designed to help those who have a image with a large files size which you would" + " like to bring down in size to use on websites without having to loss the quality of the image." + "\n" + "\n" + "--------------------------------------Warning--------------------------------------" + "\n" + "Be careful when increasing the size of the image, increasing the size of the image could result in large Temp files being " + "created and stored in " + "\n" + AppDomain.CurrentDomain.BaseDirectory + "Temp" + "\n" + "\n" + "Also be aware by pressing the “Copy Image” button you will be skipping out on a lot of the compression which means the " + "file size would be much higher then if you were to just save the image as a new file"); }
private static void SetMagickNetTempDir(string imTemptDir) { if (string.IsNullOrEmpty(imTemptDir)) { return; } if (!Directory.Exists(imTemptDir)) { throw new InvalidOperationException($"Can't call MagickNET.SetTempDirectory(...) " + $"with ... = '{imTemptDir}'"); } try { MagickNET.SetTempDirectory(imTemptDir); } catch (MagickException e) { Console.WriteLine($"Error when calling MagickNET.SetTempDirectory(...) " + $"with ... = '{imTemptDir}'", e); throw; } }
private string GerarImagem(Stream stream) { MagickNET.SetGhostscriptDirectory(Directory.GetCurrentDirectory()); MagickNET.SetTempDirectory(Path.GetTempPath()); var settings = new MagickReadSettings { Density = new Density(300, 300) }; using (var images = new MagickImageCollection()) { images.Read(stream, settings); using (var imagem = images.AppendHorizontally()) { var caminhoArquivo = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".png"); imagem.Format = MagickFormat.Png; imagem.Write(caminhoArquivo); return(caminhoArquivo); } } }
private static void SetTempDir(SettingsWrapper settings) { Directory.CreateDirectory(settings.CoreSettings.MagickImageTempDir); MagickNET.SetTempDirectory(settings.CoreSettings.MagickImageTempDir); }
public Form1() { InitializeComponent(); MagickNET.SetTempDirectory(TempFolder); }
public void SetTempDirectory_PathIsCorrect_ThrowsNoException() { MagickNET.SetTempDirectory(Path.GetTempPath()); }
public MagickTmpDir(string name = "tmp") : base(name) { MagickNET.SetTempDirectory(Dir.FullName); }
public void ShouldNotThrowExceptionWhenPathIsCorrect() { MagickNET.SetTempDirectory(Path.GetTempPath()); }
public static void pdf2image(Guid applicationId, DocFileInfo pdf, string password, DocFileInfo destFile, ImageFormat imageFormat, bool repair) { //MagickNET.SetGhostscriptDirectory("[GhostScript DLL Dir]"); //MagickNET.SetTempDirectory("[a temp dir]"); if (!pdf.FileID.HasValue) { return; } else if (PDF2ImageProcessing.ContainsKey(pdf.FileID.Value) && (!repair || PDF2ImageProcessing[pdf.FileID.Value])) { return; } else { PDF2ImageProcessing[pdf.FileID.Value] = true; } if (destFile.file_exists_in_folder(applicationId) && !repair) { PDF2ImageProcessing[pdf.FileID.Value] = false; return; } try { string cacheDir = PublicMethods.map_path(PublicConsts.MagickCacheDirectory, localPath: true); if (!Directory.Exists(cacheDir)) { Directory.CreateDirectory(cacheDir); } MagickAnyCPU.CacheDirectory = cacheDir; } catch (Exception ex) { LogController.save_error_log(applicationId, null, "SetMagickCacheDirectory", ex, ModuleIdentifier.DCT); } try { string tempDir = PublicMethods.map_path(PublicConsts.TempDirectory, localPath: true); if (!Directory.Exists(tempDir)) { Directory.CreateDirectory(tempDir); } MagickNET.SetTempDirectory(tempDir); if (!string.IsNullOrEmpty(RaaiVanSettings.GhostScriptDirectory)) { MagickNET.SetGhostscriptDirectory(RaaiVanSettings.GhostScriptDirectory); } } catch (Exception ex) { LogController.save_error_log(applicationId, null, "SetMagickTempDirectory", ex, ModuleIdentifier.DCT); } try { using (MagickImageCollection pages = new MagickImageCollection()) { MagickReadSettings settings = new MagickReadSettings() { Density = new Density(100, 100) }; bool invalidPassword = false; using (PdfReader reader = PDFUtil.open_pdf_file(applicationId, pdf, password, ref invalidPassword)) { byte[] pdfContent = PDFUtil.to_byte_array(reader); pages.Read(pdfContent, settings); } int pageNum = 0; bool errorLoged = false; foreach (MagickImage p in pages) { ++pageNum; destFile.FileName = pageNum.ToString(); destFile.Extension = imageFormat.ToString().ToLower(); if (destFile.exists(applicationId)) { continue; } try { using (MemoryStream stream = new MemoryStream()) { p.ToBitmap(imageFormat).Save(stream, imageFormat); destFile.store(applicationId, stream.ToArray()); } } catch (Exception ex) { if (!errorLoged) { errorLoged = true; LogController.save_error_log(applicationId, null, "ConvertPDFPageToImage", ex, ModuleIdentifier.DCT); } } } } } catch (Exception ex) { LogController.save_error_log(applicationId, null, "ConvertPDFToImage", ex, ModuleIdentifier.DCT); } PDF2ImageProcessing[pdf.FileID.Value] = false; }