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

ImageMagic (mogrify) and Magick.NET - JPG is edged instead rounded (AdaptiveResize)

Jan 23, 2015 at 2:30 PM

i have a problem with Magick.NET-Q16-AnyCPU and the PDF to Image conversion.

Before I'm using Magick.NET i used ImageMagick (Mogrify exe).

Also for example.

Original PDF:

mogrify.exe -resize 115 -quality 100 -format jpg "*.pdf[0]"
Example with ImageMagick Mogrify

using (var read = System.IO.File.OpenRead("4.pdf"))
    using (var write = System.IO.File.OpenWrite("4.jpg"))
        MagickReadSettings settings = new MagickReadSettings();
        settings.Density = new MagickGeometry(300);
        settings.FrameIndex = 0;
        settings.FrameCount = 1;

        using (MagickImageCollection images = new MagickImageCollection())
            images.Read(read, settings);

            using (MagickImage horizontal = images.AppendHorizontally())
                horizontal.Quality = 100;
                horizontal.AdaptiveResize(115, 163);
                horizontal.Write(write, MagickFormat.Jpg);
Example with Magick.NET Fullscreen

The output is below the code.

As comparison:
Example with ImageMagick MogrifyExample with Magick.NET Fullscreen
ImageMagick | Magick.NET

I hope you could help me to make the Magick.NET image more rounded.
The current settings are to edged.

Thanks in Advance!
Jan 23, 2015 at 2:40 PM
Why are you using AdaptiveResize instead of Resize? The command '-resize 115' translates to Resize(115,0).
Jan 23, 2015 at 3:02 PM
Edited Jan 23, 2015 at 3:15 PM
dlemstra wrote:
The command '-resize 115' translates to Resize(115,0).
Thats a little bitfaulty for me.

horizontal.Resize(115, 0);
(or 163 instead 0)

That's the result.

Example with Magick.NET

The microsoft preview pdf above works, correct. :O
But if I'm using another "simple" MS Word PDF with a little sentence i've got black screen.

Why? ...

Edit 1:
Getting error:
>mogrify.exe -resize 115 -quality 100 -format jpg "*.pdf[0]"
   **** Warning:  An error occurred while reading an XREF table.
   **** The file has been damaged.  This may have been caused
   **** by a problem while converting or transfering the file.
   **** Ghostscript will attempt to recover the data.

   **** This file had errors that were repaired or ignored.
   **** The file was produced by:
   **** >>>> Microsoft? Word 2013 <<<<
   **** Please notify the author of the software that produced this
   **** file that it does not conform to Adobe's published PDF
   **** specification.
How i can use Magick.NET with Ghostscript?
-> I'll google it.

Edit 2:
Ah, if i use mogrify to convert pdf to jpg first and then jpg to jpg (resized) it works.
mogrify.exe -format jpg "*.pdf[0]"
mogrify.exe -resize 115 -quality 100 -format jpg "*.jpg"
Jan 23, 2015 at 3:36 PM
How to convert pdf to resized jpg without using ghostscript?
using (var inputStream = File.OpenRead(inputFile))
    using (var outputStream = File.OpenWrite(outputFile))
        using (var memoryStream = new MemoryStream())
            MagickReadSettings settings = new MagickReadSettings();
            settings.Density = new MagickGeometry(300);
            settings.FrameIndex = 0;
            settings.FrameCount = 1;
            settings.Format = MagickFormat.Pdf;

            using (MagickImage image = new MagickImage(inputStream, settings))
                image.Quality = 100;
                image.Write(memoryStream, MagickFormat.Jpg);

            if (memoryStream.CanSeek) { memoryStream.Seek(0, System.IO.SeekOrigin.Begin); }
            settings.Format = MagickFormat.Jpg;
            using (MagickImage image = new MagickImage(memoryStream, settings))
                image.Quality = 100;
                image.Resize(115, 0);
                image.Write(outputStream, MagickFormat.Jpg);