Ejemplo n.º 1
0
        public ImageEditor(IPostedFile postedFile)
        {
            _Postedfile = postedFile ?? throw new ArgumentNullException($"{nameof(IPostedFile)} cannot be null.");

            _Image = Image.Load(postedFile.OpenReadStream()) as Image <Rgba32>;
            _Image.Mutate(i => i.AutoOrient());
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="args">(IPostedFile pf, string savepath)</param>
        /// <returns></returns>
        public ParameterResolverValue SaveFile(IDataLoaderContext ctx, ParameterResolverValue[] args)
        {
            if (args.Length != 2)
            {
                throw new ArgumentException("Save file takes two arguments: file, save_path");
            }
            IPostedFile file     = args[0].Value as IPostedFile;
            string      savepath = args[1].Value as string;

            if (savepath == null || file == null)
            {
                throw new ArgumentException("SaveFile: either file, path or both are null");
            }
            if (!Path.IsPathFullyQualified(savepath))
            {
                throw new ArgumentException("SaveFile the specified path is not fully qualified. Did you forget to combine paths?");
            }
            using (var stream = new FileStream(savepath, FileMode.Create))
            {
                file.OpenReadStream().CopyTo(stream);
            }
            var scope = Scope(ctx);

            scope.DeleteOnRollback(savepath);
            return(new ParameterResolverValue(true));
        }