Ejemplo n.º 1
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            if (lvImages.Items.Count > 0)
            {
                int    width          = (int)nudWidth.Value;
                int    height         = (int)nudHeight.Value;
                int    quality        = (int)nudQuality.Value;
                string outputFolder   = txtOutputFolder.Text;
                string outputFilename = txtOutputFilename.Text;

                Cursor = Cursors.WaitCursor;

                try
                {
                    foreach (ListViewItem lvi in lvImages.Items)
                    {
                        string filePath = lvi.Text;

                        if (File.Exists(filePath))
                        {
                            using (Bitmap bmp = ImageHelpers.LoadImage(filePath))
                            {
                                if (bmp != null)
                                {
                                    using (Bitmap thumbnail = ImageHelpers.CreateThumbnail(bmp, width, height))
                                    {
                                        string filename   = Path.GetFileNameWithoutExtension(filePath);
                                        string outputPath = Path.Combine(outputFolder, outputFilename.Replace("$filename", filename));
                                        outputPath = Path.ChangeExtension(outputPath, "jpg");

                                        using (Bitmap newImage = ImageHelpers.FillBackground(thumbnail, Color.White))
                                        {
                                            ImageHelpers.SaveJPEG(newImage, outputPath, quality);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    Cursor = Cursors.Default;
                    MessageBox.Show(Resources.ThumbnailsSuccessfullyGenerated, Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    DebugHelper.WriteException(ex);
                    Cursor = Cursors.Default;
                    ex.ShowError();
                }
            }
        }
Ejemplo n.º 2
0
        public IActionResult CreateThumbnails()
        {
            var images = Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(), _appSettings.Hour1400Path))
                         .Where(item => !item.Contains("thumb") && item.EndsWith(".jpg"))
                         .OrderBy(item => item)
                         .ToList();

            foreach (var image in images)
            {
                ImageHelpers.CreateThumbnail(image);
            }

            return(Ok());
        }
Ejemplo n.º 3
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            if (lvImages.Items.Count > 0)
            {
                int    width          = (int)nudWidth.Value;
                int    height         = (int)nudHeight.Value;
                int    quality        = (int)nudQuality.Value;
                string outputFolder   = txtOutputFolder.Text;
                string outputFilename = txtOutputFilename.Text;

                Cursor = Cursors.WaitCursor;

                try
                {
                    foreach (ListViewItem lvi in lvImages.Items)
                    {
                        string filePath = lvi.Text;

                        if (File.Exists(filePath))
                        {
                            using (Image img = ImageHelpers.LoadImage(filePath))
                            {
                                if (img != null)
                                {
                                    using (Image thumbnail = ImageHelpers.CreateThumbnail(img, width, height))
                                    {
                                        string filename   = Path.GetFileNameWithoutExtension(filePath);
                                        string outputPath = Path.Combine(outputFolder, outputFilename.Replace("$filename", filename));
                                        outputPath = Path.ChangeExtension(outputPath, "jpg");
                                        thumbnail.SaveJPG(outputPath, quality);
                                    }
                                }
                            }
                        }
                    }

                    Cursor = Cursors.Default;
                    // TODO: Translate
                    MessageBox.Show("Thumbnails successfully generated.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    DebugHelper.WriteException(ex);
                    Cursor = Cursors.Default;
                    ex.ShowError();
                }
            }
        }
Ejemplo n.º 4
0
        public async Task <Hour1400UploadResponse> Handle(Hour1400UploadRequest request, CancellationToken cancellationToken)
        {
            var validator = new Hour1400UploadRequestValidator();
            var result    = validator.Validate(request);

            if (!result.IsValid)
            {
                throw new Exception(result.ToString());
            }

            if (!string.Equals(request.Secret, _appSettings.Hour1400UploadSecret))
            {
                throw new Exception("Incorrect upload secret");
            }

            var saveDir = Path.Combine(Directory.GetCurrentDirectory(), _appSettings.Hour1400Path);

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

            // full path to file in temp location
            var filePath = Path.Combine(saveDir, request.FileName);

            if (!File.Exists(filePath))
            {
                if (request.Bytes.Length > 0)
                {
                    using (var stream = new FileStream(filePath, FileMode.Create))
                    {
                        await stream.WriteAsync(request.Bytes);
                    }

                    ImageHelpers.CreateThumbnail(filePath);
                }
            }

            return(new Hour1400UploadResponse());
        }
Ejemplo n.º 5
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            if (lvImages.Items.Count > 0)
            {
                int    width          = (int)nudWidth.Value;
                int    height         = (int)nudHeight.Value;
                string outputFolder   = txtOutputFolder.Text;
                string outputFilename = txtOutputFilename.Text;

                try
                {
                    foreach (ListViewItem lvi in lvImages.Items)
                    {
                        string filePath = lvi.Text;

                        if (File.Exists(filePath))
                        {
                            Image img = ImageHelpers.LoadImage(filePath);

                            if (img != null)
                            {
                                using (img = ImageHelpers.CreateThumbnail(img, width, height))
                                {
                                    string filename   = Path.GetFileNameWithoutExtension(filePath);
                                    string outputPath = Path.Combine(outputFolder, outputFilename.Replace("$filename", filename));
                                    outputPath = Path.ChangeExtension(outputPath, "jpg");
                                    img.SaveJPG(outputPath, 90);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    DebugHelper.WriteException(ex);
                    ex.ShowError();
                }
            }
        }