public async Task <bool> CompanyImagesFileProcessAsync(string filePath)
        {
            string pathWatermark = HttpContext.Current.Server.MapPath(FileConst.WatermarkIcon);
            var    imageLayer    = new ImageLayer
            {
                Image    = System.Drawing.Image.FromFile(pathWatermark, true),
                Position = new Point
                {
                    X = 15,
                    Y = 15
                }
            };

            var imageFactory = new ImageFactory(true);

            imageFactory.Load(filePath);
            if (imageLayer.Image.HorizontalResolution.InRange(95, Single.MaxValue) || imageLayer.Image.VerticalResolution.InRange(95, Single.MaxValue))
            {
                imageFactory.Resolution(96, 96);
            }

            if (imageLayer.Image.Height.InRange(419, Int32.MaxValue) || imageLayer.Image.Width.InRange(419, Int32.MaxValue))
            {
                imageFactory.Resize(new Size
                {
                    Height = 420,
                    Width  = 420
                });
            }
            ;
            imageFactory.BackgroundColor(Color.White).Save(filePath);
            return(true);
        }
 public void BackgroundColorIsChanged()
 {
     ImageFactory imageFactory = new ImageFactory();
     imageFactory.Load(@"Images\text.png");
     Image original = (Image)imageFactory.Image.Clone();
     imageFactory.BackgroundColor(Color.Yellow);
     AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the background color operation should have been applied on {0}", imageFactory.ImagePath);
 }
Exemple #3
0
        /// <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 BackgroundColorIsChanged()
        {
            ImageFactory imageFactory = new ImageFactory();

            imageFactory.Load(@"Images\text.png");
            Image original = (Image)imageFactory.Image.Clone();

            imageFactory.BackgroundColor(Color.Yellow);
            AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the background color operation should have been applied on {0}", imageFactory.ImagePath);
        }
        /// <summary>
        /// Performs the BackgroundColor effect from the ImageProcessor library.
        /// </summary>
        /// <param name="image">The image with which to apply the effect.</param>
        /// <param name="color">The color to display as the background color.</param>
        /// <returns>A new image with the BackgroundColor effect applied.</returns>
        public Image BackgroundColor(Image image, Color color)
        {
            using var factory = new ImageFactory();

            factory.Load(image);
            factory.BackgroundColor(color);

            var result = factory.Image;

            return(new Bitmap(result));
        }
        //converting graphic files, the names of which are specified in the FileNames array into the ResultDirectory directory.
        public static bool ConvertPhotos(ItemCollection FileNames, string ResultDirectory, IProgress <int> progress)
        {
            System.Drawing.Size MainPic, StandartPic, SmallPic;
            ImageProcessor.Imaging.Formats.ISupportedImageFormat newformat;

            StandartPic = new System.Drawing.Size(PicsConfig.StandartPicWidth, PicsConfig.StandartPicHeight);
            MainPic     = new System.Drawing.Size(PicsConfig.MainPicWidth, PicsConfig.MainPicHeight);
            SmallPic    = new System.Drawing.Size(PicsConfig.SmallPicWidth, PicsConfig.SmallPicHeight);
            newformat   = new ImageProcessor.Imaging.Formats.JpegFormat();

            using (ImageFactory Image_Factory = new ImageFactory(preserveExifData: true))
            {
                for (int Index = 0; Index < FileNames.Count; ++Index)
                {
                    Image_Factory.Load(FileNames[Index].ToString());
                    Image_Factory.Resize(StandartPic);
                    Image_Factory.BackgroundColor(System.Drawing.Color.White);
                    Image_Factory.Format(newformat);
                    Image_Factory.Quality(100);
                    Image_Factory.Save(ResultDirectory + "\\" + (Index + 1).ToString("D4") + ".jpg");

                    if (Index == 0)
                    {
                        Image_Factory.Resize(MainPic);
                        Image_Factory.BackgroundColor(System.Drawing.Color.White);
                        Image_Factory.Save(ResultDirectory + "\\" + (Index + 1).ToString("D4") + "_f.jpg");
                    }

                    Image_Factory.Resize(SmallPic);
                    Image_Factory.BackgroundColor(System.Drawing.Color.White);
                    Image_Factory.Save(ResultDirectory + "\\" + (Index + 1).ToString("D4") + "_sm.jpg");

                    progress.Report(Index + 1);
                }
            }

            MessageBox.Show("Image conversion is completed", "Information!", MessageBoxButton.OK, MessageBoxImage.Information);
            return(true);
        }
 public void BackgroundColorIsChanged()
 {
     using (ImageFactory imageFactory = new ImageFactory())
     {
         imageFactory.Load(ImageSources.GetFilePathByName("text.png"));
         using (Image original = imageFactory.Image.Copy())
         {
             imageFactory.BackgroundColor(Color.Yellow);
             AssertionHelpers.AssertImagesAreDifferent(
                 original,
                 imageFactory.Image,
                 "because the background color operation should have been applied on {0}",
                 imageFactory.ImagePath);
         }
     }
 }
Exemple #8
0
        public string GetPicUrl(long attaId, int width = 100, int height = 100, ThumMode mode = ThumMode.Crop, int quality = 100, WaterMarkingPosition?waterPosition = null)
        {
            var atta = AttachmentRepository.Get(attaId);

            if (atta == null)
            {
                return(null);
            }
            var thumbPath = Path.Combine(SysConfigRepository.UploadThumbDirectory,
                                         $"{mode}_{width}x{height}",
                                         atta.FilePath);
            var thumbFullPath = GetFullPath(thumbPath);

            if (!File.Exists(thumbFullPath))
            {
                var originalFullPath = GetFullPath(atta.FilePath);
                if (!File.Exists(originalFullPath))
                {
                    return(null);
                }
                using (var originalImage = new ImageFactory(true))
                {
                    ResizeMode resizeMode  = GetRezieMode(mode);
                    var        resizeLayer = new ResizeLayer(new Size(width, height), resizeMode);
                    originalImage.Load(originalFullPath)
                    .Resize(resizeLayer);
                    AddWatermark(waterPosition, originalImage);
                    originalImage.BackgroundColor(Color.White)
                    .Quality(quality)
                    .Save(thumbFullPath);
                }
            }


            return(GetFileUrl(Path.Combine(SysConfigRepository.UploadRootDirectory, thumbPath)));
        }
Exemple #9
0
 protected override ImageFactory transform(ImageFactory factory)
 {
     return(factory.BackgroundColor(_color));
 }
 public void BackgroundColorIsChanged()
 {
     using (ImageFactory imageFactory = new ImageFactory())
     {
         imageFactory.Load(ImageSources.GetFilePathByName("text.png"));
         using (Image original = imageFactory.Image.Copy())
         {
             imageFactory.BackgroundColor(Color.Yellow);
             AssertionHelpers.AssertImagesAreDifferent(
                 original,
                 imageFactory.Image,
                 "because the background color operation should have been applied on {0}",
                 imageFactory.ImagePath);
         }
     }
 }
 public IImageTransformer BackgroundColor(Color color)
 {
     _image.BackgroundColor(color);
     return(this);
 }
Exemple #12
0
 public override void Apply(ImageFactory fs)
 {
     fs = fs.BackgroundColor(color);
 }