One line convert command with -scale option

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Ethrinn
Posts: 2
Joined: 2016-03-30T02:59:06-07:00
Authentication code: 1151

One line convert command with -scale option

Post by Ethrinn »

Hi,

I am currently using imagemagick (6.7.7-10) to create thumbnails and preview images from pdf files, and I am facing an issue with the scale option :

The command line I am using right now is :

Code: Select all

convert -auto-orient -density 196 -scale 800 -background white -alpha background inputPdfFile.pdf outputJpgFile.jpg
Here is a sample of the output image :
Image
So this works well as it produces the expected jpg file, however with pdf with normal/small size fonts, the text in the output jpg is hardly readable.

And I noticed that if I am running the 2 following commands (that I thought would be a "split" version of the previous command line, using a temporary file), I obtain a much more readable result :

Code: Select all

convert -auto-orient -density 196 -background white -alpha background inputPdfFile.pdf tmp.jpg
convert -scale 800 tmp.jpg outputJpgFile.jpg
Here is a sample of the output image :
Image

I would have expected the 1 line command and the 2 lines commands to produce the same result, and as the 2 lines commands gives me a better result, is there a way to achieve the same result with a 1 line command ? (and why such a difference between those ? something about some default value parameter maybe ?)
All suggestions are welcomed :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: One line convert command with -scale option

Post by fmw42 »

Settings can come before or after the input, though some need to be before if the input is pdf. But operators must come after the input has been read. So, you need to put -scale after reading the input. Try

Code: Select all

convert -auto-orient -density 196 -background white -alpha background inputPdfFile.pdf -scale 800 outputJpgFile.jpg
With pdf input, you will get better results by using a larger density and then scaling down appropriately.
Ethrinn
Posts: 2
Joined: 2016-03-30T02:59:06-07:00
Authentication code: 1151

Re: One line convert command with -scale option

Post by Ethrinn »

I had read about the input/output option before coming here, and tried it with my heart full of hope... but it did not change anything :-?

However by testing further, I found out that the transparency in the original pdf file may have been the cause of my problem, as the suggested command did not replace the transparency by a white background, but replaced it with a black one !

So I tried with -background blue, to see clearly if the background was being replaced or not, and the "conclusion" is that -background blue -alpha Background (with no scaling) works (transparent background turns blue), but if I add the -scale 800 the background turns to black (with poor scaling).

So finally I tried some other -alpha options, and it turned out that I had my problem fixed !
Going with -alpha Opaque or -background white -alpha Remove just work great :

Code: Select all

convert -auto-orient -density 196 -background white -alpha Remove inputPdfFile.pdf -scale 800 outputJpgFile.jpg

Code: Select all

convert -auto-orient -density 196 -alpha Opaque inputPdfFile.pdf -scale 800 outputJpgFile.jpg
So that explains the difference between different commands : my 2 lines command was using a temp file with no transparency !


Thanks for the fast answer that led me to a solution :D
Now I just have to find out the best -alpha option that matches the multiple files I have to handle.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: One line convert command with -scale option

Post by fmw42 »

JPG does not support transparency. So you can just flatten the image with white or any color before saving to JPG. Since I do not have your input PDF, this is just a guess.

Code: Select all

convert -auto-orient -density 196 inputPdfFile.pdf -background white -flatten -scale 800 outputJpgFile.jpg
Post Reply