Ejemplo n.º 1
0
        public async Task WidenAsync()
        {
            string rootdir = $"{AppDomain.CurrentDomain.BaseDirectory}image";

            if (!Directory.Exists(rootdir))
            {
                Directory.CreateDirectory(rootdir);
            }

            string img = await RankaMessageGrabber.GetLastImage(Context).ConfigureAwait(false);

            var input = RankaFileHandler.DownloadImage(img);

            try
            {
                using Process imageMagick             = new Process();
                imageMagick.StartInfo.UseShellExecute = false;
                imageMagick.StartInfo.FileName        = "convert";
                imageMagick.StartInfo.Arguments       = $"\"{input}\" -resize \"2000x500!\" -quality 100 \"{rootdir}/output.png\"";
                imageMagick.StartInfo.CreateNoWindow  = true;
                imageMagick.Start();
                imageMagick.WaitForExit();

                await RankaFileUploadAsync($"{rootdir}/output.png").ConfigureAwait(false);
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        public async Task MakeTextImgAsync([Remainder][Summary("Your quote")] string quote)
        {
            if (quote == null)
            {
                throw new ArgumentNullException(nameof(quote), "Nothings written");
            }

            string rootdir = $"{AppDomain.CurrentDomain.BaseDirectory}image";

            if (!Directory.Exists(rootdir))
            {
                Directory.CreateDirectory(rootdir);
            }

            string img = await RankaMessageGrabber.GetLastImage(Context).ConfigureAwait(false);

            var input = RankaFileHandler.DownloadImage(img);

            try
            {
                await Task.Run(() =>
                {
                    using Process imageMagick             = new Process();
                    imageMagick.StartInfo.UseShellExecute = false;
                    imageMagick.StartInfo.FileName        = "convert";
                    imageMagick.StartInfo.Arguments       = $"\"{input}\" -fill black -font /usr/share/fonts/truetype/freefont/FreeSansBoldOblique.ttf -pointsize 64 -size 480x -gravity Center -annotate +0+4 \"{quote}\" \"{rootdir}/output.png\"";
                    imageMagick.StartInfo.CreateNoWindow  = true;
                    imageMagick.Start();
                    imageMagick.WaitForExit();
                }).ConfigureAwait(false);

                await RankaFileUploadAsync($"{rootdir}/output.png").ConfigureAwait(false);
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 3
0
        public async Task CubeUpAsync()
        {
            string rootdir = $"{AppDomain.CurrentDomain.BaseDirectory}image";

            if (!Directory.Exists(rootdir))
            {
                Directory.CreateDirectory(rootdir);
            }

            string img = await RankaMessageGrabber.GetLastImage(Context).ConfigureAwait(false);

            var input = RankaFileHandler.DownloadImage(img);

            try
            {
                await Task.Run(() =>
                {
                    using Process imageMagick             = new Process();
                    imageMagick.StartInfo.UseShellExecute = false;
                    imageMagick.StartInfo.FileName        = "convert";
                    imageMagick.StartInfo.Arguments       = $"\"{input}\" -resize \"256x256\" \"{rootdir}/top.png\"";
                    imageMagick.StartInfo.CreateNoWindow  = true;
                    imageMagick.Start();
                    imageMagick.WaitForExit();
                }).ConfigureAwait(false);

                await Task.Run(() =>
                {
                    using Process imageMagick             = new Process();
                    imageMagick.StartInfo.UseShellExecute = false;
                    imageMagick.StartInfo.FileName        = "convert";
                    imageMagick.StartInfo.Arguments       = $"\"{input}\" -resize \"256x256\" \"{rootdir}/left.png\"";
                    imageMagick.StartInfo.CreateNoWindow  = true;
                    imageMagick.Start();
                    imageMagick.WaitForExit();
                }).ConfigureAwait(false);

                await Task.Run(() =>
                {
                    using Process imageMagick             = new Process();
                    imageMagick.StartInfo.UseShellExecute = false;
                    imageMagick.StartInfo.FileName        = "convert";
                    imageMagick.StartInfo.Arguments       = $"\"{input}\" -resize \"256x256\" \"{rootdir}/right.png\"";
                    imageMagick.StartInfo.CreateNoWindow  = true;
                    imageMagick.Start();
                    imageMagick.WaitForExit();
                }).ConfigureAwait(false);

                await Task.Run(() =>
                {
                    using Process imageMagick             = new Process();
                    imageMagick.StartInfo.UseShellExecute = false;
                    imageMagick.StartInfo.FileName        = "convert";
                    imageMagick.StartInfo.Arguments       = $"\"{rootdir}/top.png\" -resize 260x301! -alpha set -background none -shear 0x30 -rotate -60 -gravity center -crop 960x301+0+0 \"{rootdir}/top_shear.png\"";
                    imageMagick.StartInfo.CreateNoWindow  = true;
                    imageMagick.Start();
                    imageMagick.WaitForExit();
                }).ConfigureAwait(false);

                await Task.Run(() =>
                {
                    using Process imageMagick             = new Process();
                    imageMagick.StartInfo.UseShellExecute = false;
                    imageMagick.StartInfo.FileName        = "convert";
                    imageMagick.StartInfo.Arguments       = $"\"{rootdir}/left.png\" -resize 260x301! -alpha set -background none -shear 0x30 \"{rootdir}/left_shear.png\"";
                    imageMagick.StartInfo.CreateNoWindow  = true;
                    imageMagick.Start();
                    imageMagick.WaitForExit();
                }).ConfigureAwait(false);

                await Task.Run(() =>
                {
                    using Process imageMagick             = new Process();
                    imageMagick.StartInfo.UseShellExecute = false;
                    imageMagick.StartInfo.FileName        = "convert";
                    imageMagick.StartInfo.Arguments       = $"\"{rootdir}/right.png\" -resize 260x301! -alpha set -background none -shear 0x-30 \"{rootdir}/right_shear.png\"";
                    imageMagick.StartInfo.CreateNoWindow  = true;
                    imageMagick.Start();
                    imageMagick.WaitForExit();
                }).ConfigureAwait(false);

                await Task.Run(() =>
                {
                    using Process imageMagick             = new Process();
                    imageMagick.StartInfo.UseShellExecute = false;
                    imageMagick.StartInfo.FileName        = "bash";
                    imageMagick.StartInfo.Arguments       = $"-c \"convert ./image/left_shear.png ./image/right_shear.png +append \\( ./image/top_shear.png -repage +0-149 \\) -background none -layers merge +repage -resize 80% ./image/output.png\"";
                    imageMagick.StartInfo.CreateNoWindow  = true;
                    imageMagick.Start();
                    imageMagick.WaitForExit();
                }).ConfigureAwait(false);

                await RankaFileUploadAsync($"{rootdir}/output.png").ConfigureAwait(false);
            }
            catch (Exception)
            {
                throw;
            }
        }