コード例 #1
0
        protected override string MakeImage(string Path, List <string> Items)
        {
            if ((this.MaximumCount < this.CurrentCount + 1) && (this.Settings as GenerateTextImageSettings).Number == NumberType.Limited)
            {
                if (this.Images.Count == 0)
                {
                    throw new Exception("Image limit reached and no used images available.");
                }

                return(this.Images[Random.Next(this.Images.Count)]);
            }

            // Create directories
            IOHelper.CreateDirectory(Path);

            string text = this.SelectText((this.Settings as GenerateTextImageSettings).StringSelect);


            // Save
            string imagePath = IO.Path.Combine(Path, this.MakeFileName(text.Select(StringSelectType.Word, true),
                                                                       (this.Settings as GenerateTextImageSettings).
                                                                       Names)) + ".jpg";

            this.Images.Add(imagePath);

            // Make image
            Bitmap image =
                BitmapHelper.Make(
                    this.Random.Next((this.Settings as GenerateTextImageSettings).WidthMin,
                                     (this.Settings as GenerateTextImageSettings).WidthMax), this.Random.Next(
                        (this.Settings as GenerateTextImageSettings).HeightMin,
                        (this.Settings as GenerateTextImageSettings).HeightMax),
                    (this.Settings as GenerateTextImageSettings).BackgroundColorSettings);

            // Draw text
            image.DrawText(text, (this.Settings as GenerateTextImageSettings).Font);


            if ((this.Settings as GenerateTextImageSettings).ModificationsNoise)
            {
                image.DrawNoise();
            }

            image.Save(imagePath);

            return(imagePath);
        }
コード例 #2
0
        protected override string MakeImage(string Path, List <string> Items)
        {
            // Create directories
            IOHelper.CreateDirectory(Path);

            string text = string.Empty;

            for (int i = 0; i < Items.Count; i++)
            {
                text += Items[i] + "\r\n";
            }

            text = text.Trim(' ', '\r', '\n');


            // Save
            string imagePath = IO.Path.Combine(Path, this.MakeFileName(text.Select(StringSelectType.Word, true),
                                                                       (this.Settings as GenerateKeywordsImageSettings).
                                                                       Names)) + ".jpg";

            this.Images.Add(imagePath);

            // Make image
            Bitmap image =
                BitmapHelper.Make(
                    this.Random.Next((this.Settings as GenerateKeywordsImageSettings).WidthMin,
                                     (this.Settings as GenerateKeywordsImageSettings).WidthMax), this.Random.Next(
                        (this.Settings as GenerateKeywordsImageSettings).HeightMin,
                        (this.Settings as GenerateKeywordsImageSettings).HeightMax),
                    (this.Settings as GenerateKeywordsImageSettings).BackgroundColorSettings);

            // Draw text
            image.DrawText(text, (this.Settings as GenerateKeywordsImageSettings).Font);


            if ((this.Settings as GenerateKeywordsImageSettings).ModificationsNoise)
            {
                image.DrawNoise();
            }

            image.Save(imagePath);


            return(imagePath);
        }
コード例 #3
0
        protected override string MakeImage(string Path, List <string> Items)
        {
            // Create directories
            IOHelper.CreateDirectory(Path);

            string keyword = Items[this.Random.Next(Items.Count)];

            // Save
            string imagePath = IO.Path.Combine(Path, this.MakeFileName(keyword,
                                                                       (this.Settings as GenerateKeywordImageSettings).
                                                                       Names)) + ".jpg";

            this.Images.Add(imagePath);

            // Make image
            Bitmap image =
                BitmapHelper.Make(
                    this.Random.Next((this.Settings as GenerateKeywordImageSettings).WidthMin,
                                     (this.Settings as GenerateKeywordImageSettings).WidthMax), this.Random.Next(
                        (this.Settings as GenerateKeywordImageSettings).HeightMin,
                        (this.Settings as GenerateKeywordImageSettings).HeightMax),
                    (this.Settings as GenerateKeywordImageSettings).BackgroundColorSettings);

            // Draw text
            image.DrawText(keyword, (this.Settings as GenerateKeywordImageSettings).Font);

            if ((this.Settings as GenerateKeywordImageSettings).ModificationsNoise)
            {
                image.DrawNoise();
            }

            image.Save(imagePath);


            return(imagePath);
        }
コード例 #4
0
        protected override string MakeImage(string Path, List <string> Items)
        {
            // Create directories
            IOHelper.CreateDirectory(Path);

            string keyword = Items[this.Random.Next(Items.Count)];

            // Select image
            string originalImagePath = this.Select();

            // HTTP
            if (!originalImagePath.ToLower().StartsWith("http"))
            {
                // File
                if (originalImagePath.Contains("\\Files\\"))
                {
                    string directories = originalImagePath.Substring(originalImagePath.LastIndexOf("\\Files\\") + 7);
                    if (directories.Contains("\\"))
                    {
                        IOHelper.CreateDirectory(IO.Path.Combine(Path, directories));
                    }
                }

                // Save
                string imagePath = IO.Path.Combine(Path, this.MakeFileName(originalImagePath.Substring(originalImagePath.LastIndexOf("\\") + 1), keyword,
                                                                           (this.Settings as ModifyBorderKeywordImageSettings).Rename)) + ".jpg";
                this.Images.Add(imagePath);

                // Open original image
                Image originalImage = Image.FromFile(originalImagePath);
                if ((this.Settings as ModifyBorderKeywordImageSettings).ModificationsImageNoise)
                {
                    ((Bitmap)originalImage).DrawNoise();
                }

                // Make image
                int left = this.Random.Next((this.Settings as ModifyBorderKeywordImageSettings).LeftMin,
                                            (this.Settings as ModifyBorderKeywordImageSettings).LeftMax);

                int right = this.Random.Next((this.Settings as ModifyBorderKeywordImageSettings).RightMin,
                                             (this.Settings as ModifyBorderKeywordImageSettings).RightMax);

                int top = this.Random.Next(
                    (this.Settings as ModifyBorderKeywordImageSettings).TopMin,
                    (this.Settings as ModifyBorderKeywordImageSettings).TopMax);

                int bottom = this.Random.Next(
                    (this.Settings as ModifyBorderKeywordImageSettings).BottomMin,
                    (this.Settings as ModifyBorderKeywordImageSettings).BottomMax);


                Bitmap image =
                    BitmapHelper.Make(originalImage.Width + left + right,
                                      originalImage.Height + top + bottom,
                                      (this.Settings as ModifyBorderKeywordImageSettings).BackgroundColorSettings);

                // Draw text
                Bitmap textImage = image.Clone(new Rectangle(0, image.Height - bottom, image.Width, bottom),
                                               System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                textImage.DrawText(keyword, (this.Settings as ModifyBorderKeywordImageSettings).Font);


                // Insert text image
                image.DrawImage(textImage, 0, originalImage.Height + top);

                if ((this.Settings as ModifyBorderKeywordImageSettings).ModificationsBorderNoise)
                {
                    image.DrawNoise();
                }

                // Insert original image into new one
                image.DrawImage((Bitmap)originalImage, (left + right) / 2, (top + bottom) / 2);

                image.Save(imagePath);

                originalImagePath = imagePath;
            }

            return(originalImagePath);
        }
コード例 #5
0
        protected override string MakeImage(string Path, List <string> Items)
        {
            if ((this.MaximumCount < this.CurrentCount + 1) && (this.Settings as ModifyBorderTextImageSettings).Number == NumberType.Limited)
            {
                if (this.Images.Count == 0)
                {
                    throw new Exception("Image limit reached and no used images available.");
                }

                return(this.Images[Random.Next(this.Images.Count)]);
            }

            // Create directories
            IOHelper.CreateDirectory(Path);

            // Select image
            string originalImagePath = this.Select();

            // HTTP
            if (!originalImagePath.ToLower().StartsWith("http"))
            {
                // File
                if (originalImagePath.Contains("\\Files\\"))
                {
                    string directories = originalImagePath.Substring(originalImagePath.LastIndexOf("\\Files\\") + 7);
                    if (directories.Contains("\\"))
                    {
                        IOHelper.CreateDirectory(IO.Path.Combine(Path, directories));
                    }
                }

                string text = SelectText((this.Settings as ModifyBorderTextImageSettings).StringSelect);

                string imagePath = IO.Path.Combine(Path,
                                                   this.MakeFileName(Path, text.Select(StringSelectType.Word, true),
                                                                     (this.Settings as ModifyBorderTextImageSettings).Rename)) + ".jpg";
                this.Images.Add(imagePath);

                // Open original image
                Image originalImage = Image.FromFile(Path);
                if ((this.Settings as ModifyBorderTextImageSettings).ModificationsImageNoise)
                {
                    ((Bitmap)originalImage).DrawNoise();
                }

                // Make image
                int left = this.Random.Next((this.Settings as ModifyBorderTextImageSettings).LeftMin,
                                            (this.Settings as ModifyBorderTextImageSettings).LeftMax);

                int right = this.Random.Next((this.Settings as ModifyBorderTextImageSettings).RightMin,
                                             (this.Settings as ModifyBorderTextImageSettings).RightMax);

                int top = this.Random.Next(
                    (this.Settings as ModifyBorderTextImageSettings).TopMin,
                    (this.Settings as ModifyBorderTextImageSettings).TopMax);

                int bottom = this.Random.Next(
                    (this.Settings as ModifyBorderTextImageSettings).BottomMin,
                    (this.Settings as ModifyBorderTextImageSettings).BottomMax);


                Bitmap image =
                    BitmapHelper.Make(originalImage.Width + left + right,
                                      originalImage.Height + top + bottom,
                                      (this.Settings as ModifyBorderTextImageSettings).BackgroundColorSettings);

                // Draw text
                Bitmap textImage = image.Clone(new Rectangle(0, image.Height - bottom, image.Width, bottom),
                                               System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                textImage.DrawText(text, (this.Settings as ModifyBorderTextImageSettings).Font);


                // Insert text image
                image.DrawImage(textImage, 0, originalImage.Height + top);

                if ((this.Settings as ModifyBorderTextImageSettings).ModificationsBorderNoise)
                {
                    image.DrawNoise();
                }

                // Insert original image into new one
                image.DrawImage((Bitmap)originalImage, (left + right) / 2, (top + bottom) / 2);

                image.Save(imagePath);

                originalImagePath = imagePath;
            }

            return(originalImagePath);
        }