Tuesday, December 13, 2011

The great convert tool of ImageMagick


It's of those days where you are just wondering why you are failing to program as usual. Your mind is sleepy, your thinking slow. While drinking a cup of coffee in order to awake your brain (even if you know that in such situations coffee just fails) you listen something not so important (as most things sound at the beginning). "I have a large pdf file how do I reduce its size?".
(I want to inform you now that this article is not about pdf resizing).
Then, as the coffee sinks in, along with this words, there is another question on the horizon. Can you reduce anything without losing something? Of course not. Anyway, that's not my point.

I decided to try and find how to do that, with linux, using scripts. After a couple of google searches I found ghostscript. It was quite a fail, since the pdf was at its minimum size that ghostscript could convert, so it made it bigger.

Then, I looked at my pictures. I always do this when I fail to find a solution for something. Great images, with high resolution. Hang on! What about making every pdf page as a jpg file and then reducing the resolution of those images, and after that putting all these images back as pdf pages?

If you have the knowledge of a normal user this could mean hours of work, especially if pdf has 100 pages. Imagine having at the end another bigger pdf file.

So, I realised that it was a lot of work. What about using a script to do that? Here it comes the convert of ImageMagick!

I might failed to find an optimised solution for the pdf problem, but I've found a great tool! Convert is a terminal program created by ImageMagick that can convert any image file into another by user's will. In addition, it is open source, written in C.

You can reduce your size of your images, transform them, skew them, flip them, change colours with mapping and more more advance image things! It's like having photoshop in a small program, without the heavy brashes and tools. Type the commands, you have your image converted. Just visit man pages on your linux. Or visit  http://www.imagemagick.org/script/convert.php to download a version with GUI or for a different operating system.

For the story, I used this to convert my pdf:
convert input.pdf -scale 500 output.pdf
And got a smaller file with a terrible resolution.
Anyone knows anything about it?

That's a story about how something irrelevant results to an exploration of another irrelevant thing (but useful).


So, even if you are going to fail, never mind, explore! Even if it's pangolins! :)

No comments:

Post a Comment