Beispiel #1
0
    void GenerateThumbSq(Ffmpeg ffmpeg, string localSourceFile, string localThumbSqFile, MovieMetadata mm)
    {
        ffmpeg.ExtractFrame(localSourceFile, localThumbSqFile, GetThumbnailSeconds(mm));

        using (var wand = new MagickWand(localThumbSqFile))
        {
            var width  = (double)wand.ImageWidth;
            var height = (double)wand.ImageHeight;
            var aspect = width / height;

            if (aspect >= THUMB_SQ_ASPECT)
            {
                var newWidth = (width / height) * THUMB_SQ_HEIGHT;

                // scale image to final height
                wand.ScaleImage((uint)newWidth, THUMB_SQ_HEIGHT);

                // crop sides as needed
                wand.CropImage(THUMB_SQ_WIDTH, THUMB_SQ_HEIGHT, (int)(newWidth - THUMB_SQ_WIDTH) / 2, 0);
            }
            else
            {
                var newHeight = THUMB_SQ_WIDTH / (width / height);

                // scale image to final width
                wand.ScaleImage(THUMB_SQ_WIDTH, (uint)newHeight);

                // crop top and bottom as needed
                wand.CropImage(THUMB_SQ_WIDTH, THUMB_SQ_HEIGHT, 0, (int)(newHeight - THUMB_SQ_HEIGHT) / 2);
            }

            // sharpen after potentially resizing
            // http://www.imagemagick.org/Usage/resize/#resize_unsharp
            wand.UnsharpMaskImage(0, 0.7, 0.7, 0.008);

            wand.WriteImage(localThumbSqFile, true);

            mm.ThumbSqHeight = THUMB_SQ_HEIGHT;
            mm.ThumbSqWidth  = THUMB_SQ_WIDTH;
        }
    }
Beispiel #2
0
        public void Generate()
        {
            using (var wand = new MagickWand(_sourcePath))
            {
                var width  = (double)wand.ImageWidth;
                var height = (double)wand.ImageHeight;
                var aspect = width / height;

                if (aspect >= Aspect)
                {
                    var newWidth = (width / height) * FinalHeight;

                    // scale image to final height
                    wand.ScaleImage((uint)newWidth, FinalHeight);

                    // crop sides as needed
                    wand.CropImage(FinalWidth, FinalHeight, (int)(newWidth - FinalWidth) / 2, 0);
                }
                else
                {
                    var newHeight = FinalWidth / (width / height);

                    // scale image to final width
                    wand.ScaleImage(FinalWidth, (uint)newHeight);

                    // crop top and bottom as needed
                    wand.CropImage(FinalWidth, FinalHeight, 0, (int)(newHeight - FinalHeight) / 2);
                }

                // sharpen after potentially resizing
                // http://www.imagemagick.org/Usage/resize/#resize_unsharp
                wand.UnsharpMaskImage(0, 0.7, 0.7, 0.008);

                wand.WriteImage(_destPath, true);
            }

            ExecuteJpegOptimAsync(_destPath);
            ExecuteJpegTranAsync(_destPath);
        }