Exemple #1
0
        public void Run(ICommandInteraction writer, DecimalIntegerToken width, DecimalIntegerToken height)
        {
            if (width.Value <= 0 || height.Value <= 0)
            {
                throw new RecoverableException("Width and height must be positive values");
            }

            var image = new Bitmap((int)width.Value, (int)height.Value);

            using (var graphics = Graphics.FromImage(image))
            {
                var imageSize = new Rectangle(0, 0, (int)width.Value, (int)height.Value);
                graphics.FillRectangle(Brushes.White, imageSize);
            }
            writer.WriteRaw(InlineImage.Encode(image));
        }
        public void Run(ICommandInteraction writer, PathToken pathToImage)
        {
            if (!File.Exists(pathToImage.Value))
            {
                writer.WriteError($"No such file {pathToImage.Value}");
                return;
            }


            using (var file = new FileStream(pathToImage.Value, FileMode.Open))
            {
                if (!CheckFormat(file))
                {
                    writer.WriteError("Bad image format. Supported formats: jpeg, png");
                    return;
                }

                writer.WriteRaw(InlineImage.Encode(file));
            }
        }
        public void Run(ICommandInteraction writer, DecimalIntegerToken widthToken, DecimalIntegerToken heightToken)
        {
            // This method creates white rectangle, intended for testing purposes.
            var width  = (int)widthToken.Value;
            var height = (int)heightToken.Value;

            if (width <= 0 || height <= 0)
            {
                throw new RecoverableException("Width and height must be positive values");
            }

            var bytes = new byte[width * height * RawImageData.PixelFormat.GetColorDepth()];

            for (var i = 0; i < bytes.Length; ++i)
            {
                bytes[i] = (byte)0xFF;
            }
            var image = new RawImageData(bytes, width, height);

            writer.WriteRaw(InlineImage.Encode(image.ToPng()));
        }
Exemple #4
0
        public void Run(ICommandInteraction writer, PathToken pathToImage)
        {
            if (!File.Exists(pathToImage.Value))
            {
                writer.WriteError($"No such file {pathToImage.Value}");
                return;
            }

            try
            {
                var image = new Bitmap(pathToImage.Value);
                if (!ImageFormat.Jpeg.Equals(image.RawFormat) && !ImageFormat.Png.Equals(image.RawFormat))
                {
                    writer.WriteError("Bad image format. Supported formats: jpeg, png");
                    return;
                }
                writer.WriteRaw(InlineImage.Encode(image));
            }
            catch (Exception e)
            {
                writer.WriteError($"There was an error when loading the image: {(e.Message)}");
            }
        }