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?".
I'm preparing some documents for translation, and came around an issue.
This one: http://www.komyokk.co.jp/pdata/tpdf/104U_1.pdf
When you look it in the PDF viewer, it correctly shows page boundary as printed.
But when you render it with imagick, it adds huge margins to the resulting image.
I feel like there's a simple solution I'm overlooking.
If you look at the PDF file in a plain text editor, you will see it has a media box and also a smaller cropbox. By default IM ignores the cropbox, but can be told to use it:
convert -density 300 -define pdf:use-cropbox=true pdf:"104U_1.pdf" -background white -alpha on -layers flatten -resize "1366x>" -gravity north -crop 1024x180+0+180 png48:"104U.pdf"
Does almost what I want, but it removes transparency present in the original document.
The key point seems to be the "-layers flatten", but when I remove it, -resize does not work either.
I've also tried -layers merge and various -background settings, but that randomly removes layers from resulting image and/or making image turn black'ish in some viewers.
Is there a solution?
This creates a PNG format file with a filename that ends with ".pdf", which seems a bad idea. Why do you do this? It will confuse other software, for example Adobe Reader thinks it is a corrupt PDF file.
This creates a PNG format file with a filename that ends with ".pdf", which seems a bad idea. Why do you do this? It will confuse other software, for example Adobe Reader thinks it is a corrupt PDF file.
Sorry, that was a typo. Indeed, in the actual code it was .png.
If you want to write to two or more outputs, such as info: and a file, you need to use the "+write" or "-write" command for all except the last, like this:
That's not quite the question I have.
In the example above, I've replaced the png:… with info: for illustrative purposes. The saved PNG do match the dimensions shown in text output.
The "-background" setting does have a default. The undocumented "+background" sets this.
But "-alpha" isn't a setting, and a default doesn't make sense. Sadly IM doesn't check the sign, so takes whatever follows as the argument to "-alpha" and either throws an error or gets confused.
AnrDaemon wrote:Is there a way to preserve alpha while merging layers?
I thought you didn't want to merge layers? There is only one image, so the only point in merging layers is to flatten the image against a background, which removes alpha, and you don't want that.