Convert adds white margins

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
dunedain
Posts: 4
Joined: 2013-01-09T04:13:38-07:00
Authentication code: 6789

Convert adds white margins

Post by dunedain »

Hi!

I've googling around like crazy and I haven't been able to find a solution to my problem. I'm using ImageMagicks convert to create png images from a pdf file. The problem is that on every pdf I try it adds white margins on the created images and I can't find how to get rid of them :?

I'm using ImageMagick 6.6.0-4 on a Debian 6.0 server. The command I execute is this:

convert "PDF_FILE" -colorspace RGB -resize 490x694\! -density 300 -quality 100 "PNG_FILE"

I've tried it with and without the resize, with crop, with no parameters at all...

Here is a PDF file I've tried and the resulting PNG file:

The PDF: https://dl.dropbox.com/u/4279061/epeich.pdf
A PNG image, the first page of the PDF file: https://dl.dropbox.com/u/4279061/340.png

I guess it's something simple... but as a newbie... I can't find the solution. Thanks for the help!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert adds white margins

Post by fmw42 »

I suspect it is some feature in the PDF file such as bounding box. You can either try using Ghostscript directly with more options than IM uses with GS or just trim the result and add any border that you want, such as


convert -colorspace RGB epeich.pdf[0] +repage -resize 490x694\! -density 300 -quality 100 -trim -bordercolor white -border 10 result.png

Here I have just used the first page as noted by [0]. Also for vector images, you should put -colorspace before reading the input.
dunedain
Posts: 4
Joined: 2013-01-09T04:13:38-07:00
Authentication code: 6789

Re: Convert adds white margins

Post by dunedain »

Thanks!!! Worked like a charm :D
dunedain
Posts: 4
Joined: 2013-01-09T04:13:38-07:00
Authentication code: 6789

Re: Convert adds white margins

Post by dunedain »

Woops! Maybe I wrote too fast. Now it works as wanted, no white margins, but it doesn't do to the specified size :(

The output images are 368x544 even it has " -resize 490x694\! " Here is an generated image:

https://dl.dropbox.com/u/4279061/344.png

Thanks for the fast response :D
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert adds white margins

Post by fmw42 »

try putting the -trim before the resize


convert -colorspace RGB epeich.pdf[0] +repage -trim +repage -resize 490x694\! -density 300 -quality 100 result.png

or


convert -colorspace RGB epeich.pdf[0] +repage -trim +repage -bordercolor white -border XX -resize 490x694\! -density 300 -quality 100 result.png


Use the border value XX as desired for padding.
dunedain
Posts: 4
Joined: 2013-01-09T04:13:38-07:00
Authentication code: 6789

Re: Convert adds white margins

Post by dunedain »

Thanks! It worked perfectly :D
Post Reply