[Tex/LaTex] How to crop background from image automatically

cropgraphicspackages

I have a Google Docs drawing that is a small scheme. However, this small scheme is surrounded by a lot of background that occupies a lot of useless space.

enter image description here

I do not want to remove the background manually because I may need the extra space in the future.

I know Latex has a lot of image packages, so I was wondering if there is some package that I can use to automatically detect that useless background and crop my image so I do not have all that white space around it.

I know some of you will suggest the external tool pdfcrop. I have experimented with it, but it does not crop the image at all.

Here is the png image file and here is the pdf version downloaded with Gdocs.

Best Answer

You do not need a cropped copy with a external program, only add some options to \includegraphics. This MWE show the same image twice (renamed to image.png) , with and without the useless background. Both images are inside a framed box to show the edges:

MWE

\documentclass{article}
\usepackage{graphicx}
\begin{document}

\section*{Original image} 

\fbox{\includegraphics[width=\linewidth]{image.png}}

\section*{Trimmed and clipped image} 

\fbox{\includegraphics[width=\linewidth,trim=6.5cm 6cm 6.5cm 4cm,clip]{image.png}}

\end{document}

Edit: Since the goal seem to be the automatic cropping more that avoid a cropped copy, this has been perfectly solved in the comments (with an external tool) as far I know, so only put in practice to in a MWE.

The following code with a poorman's macro added to the above MWE:

\section*{Automatic crop}
Note: compile with \verb|--shell-escape|\\

\newcommand\cropped[1]{%
    \immediate\write18{convert -trim #1.png #1cropped.png}%
    \includegraphics[width=\linewidth]{#1cropped.png}}

\fbox{\cropped{image}}

Will produce this image automatically:

MWE

Really the cropping was not make really by LaTeX and neeed one extra file, but who cares? Anyway is done while running pdflatex.