This project has moved and is read-only. For the latest updates, please go here.

trying to convert a command line to VB, getting close but cant get gravity to work

Oct 7, 2016 at 10:26 PM
Edited Oct 7, 2016 at 10:28 PM
Using VB.NET 2010, I am trying to resize a image to be 96x72, the image itself will be xx X 72 when resized and I want to center it in a colored box. The convert command line is

convert test.jpg -quality 85 -thumbnail 96x72">" -background antiquewhite3 -gravity center -extent 96x72 test2.jpg

I am getting close with .NET but the image is sticking to the left of the image and I can't seem to CENTER it, I have tried a variety of things and I am close, but I need to center the image.
    Using image As New MagickImage("C:\Users\User\Desktop\test\newImageMagick\test.jpg")

        '-quality 85 -thumbnail 96x72">"  -background antiquewhite3 -gravity center -extent 96x72 
        image.Quality = 85

        'Create thumnail that is 96 pixels wide and 72 pixels high
        image.Thumbnail(96, 72)

        'since the test image ends up being 54x72 (in this case), now we want to make it 96x72 with the image in the center and a background border of antique white on both sides.
        'set the background
        image.BackgroundColor = ImageMagick.MagickColors.AntiqueWhite

        'image.Settings.SetDefine(MagickFormat.Jpeg, "-gravity", "center") 'didn't work.
        image.Composite(image, ImageMagick.Gravity.Center) 'tried a variety of  CompositeOperators)

        image.Extent(96, 72)

        ' Save the result
    End Using
Oct 9, 2016 at 4:09 PM
You can just do this:
image.Thumbnail(96, 72);
image.BackgroundColor = ImageMagick.MagickColors.AntiqueWhite;
image.Extent(96, 72, Gravity.Center);
Oct 10, 2016 at 3:54 PM
Perfect, Thank You !