2

I'm planning to use MetaUML to automatically generate UML diagrams (as images) and display them.

I found that there is an utility, mptopdf, that helps generating the output as a PDF file:

mptopdf example.mp

Is there any way that I can generate the output as an image file (png/jpg, or any format)? Please suggest. Am entirely new to this.

  • Welcome to tex.sx! Note that you don't have to (and shouldn't) sign with your name since it automatically appears in the lower right corner of your post. – Hendrik Vogt Jan 16 '11 at 16:10
3

If you have ImageMagick installed, you can easily convert the pdf to any other image format:

convert -trim +repage example.pdf example.png

You can replace .png by any other supported format. The -trim +repage option removes unnecessary whitespace surrounding the image and sets the canvas size to the trimmed image. You can also add -density 300 (or any other number) to specify the dpi of the resulting raster image. For example,

convert -density 600 -trim +repage example.pdf -resize 200% example.png
  • This is wonderful! With IM I can even scale up the image size. Thanks! However, I'll be using this in context of a web application. I was wondering if the output image could be generated "directly". Becasue, creating a PDF and then converting it requires both time and space. – Barun Jan 17 '11 at 5:43
  • I have never used MetaUML, so I can't tell. Compiling the metapost to ps instead of pdf and converting from there might be a bit faster (be sure to do some real world test). But basically I think this is the process that is usually used to get an image file out of TeX code. – Caramdir Jan 17 '11 at 6:15
  • In case someone was as clueless as I was on where to put -density and -resize, it's convert -density 600 -trim +repage example.pdf -resize 200% example.png. Higher sampling density makes the output picture sharper, which is needed when resize up. – Apiwat Chantawibul Jan 2 '14 at 7:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.