Page 1 of 1

Convert adds white margins

Posted: 2013-01-09T04:25:05-07:00
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!

Re: Convert adds white margins

Posted: 2013-01-09T12:23:49-07:00
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.

Re: Convert adds white margins

Posted: 2013-01-09T12:51:07-07:00
by dunedain
Thanks!!! Worked like a charm :D

Re: Convert adds white margins

Posted: 2013-01-09T13:01:06-07:00
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

Re: Convert adds white margins

Posted: 2013-01-09T20:07:32-07:00
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.

Re: Convert adds white margins

Posted: 2013-01-10T04:29:13-07:00
by dunedain
Thanks! It worked perfectly :D