Here is a very different approach because the code in https://tex.stackexchange.com/a/330885/36296 had very different constraints. Or I just became wiser and less obsessed with framed.sty.
This is second version: the first one used a multiline \parshape but it is hard then to take into account long titles over multiple lines; it is simpler to do each time a \par and use \prevgraf to check if we have reached bottom of picture. Thus the new version uses \parshape with n=1 line specification.
edit: well finally I have dropped entirely the \parshape thing and use only adjustments of \leftskip. I also take this opportunity to simply the code for chapter titles, because it came from a context where \parskip was positive and not to be modified, hence looked unnecessarily weird. And, I add use of package needspace to make sure there is enough room at bottom of page for graphics. The present code will easily left the chapter title at bottom of page, if one wants it to stick to the graphics below it, then it is possible but one needs to move some code from the section style to the chapter style, taking into account that in the example the \setsectocdeco commands are already used before \chapter. But with the present code, they may as well be used after the \chapter as we don't worry about glueing the chapter title to the graphics.
Also I have added the better handling of section numbers and page numbers so that long titles do not go underneath them on subsequent lines (this is matter of taste). And the last chapter has no associated graphics to show it does work in that case too.
note: in the image below the jpeg decorating the second chapter has some whitespace all around the square, which explains why it looks shifted to the right and to the bottom. This comes from the jpeg not from the LaTeX code.
% Image credits:
% Par Mallowtek — Travail personnel, CC BY-SA 3.0,
% https://commons.wikimedia.org/w/index.php?curid=20438883
% Par Jean-Luc W — Travail personnel, CC BY-SA 3.0,
% https://commons.wikimedia.org/w/index.php?curid=10002415
\documentclass[a4paper]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\usepackage{graphicx}
%\usepackage{xcolor}
\usepackage{etoc}
\usepackage{mwe}
\usepackage{needspace}
%\usepackage[linktoc=all]{hyperref}% it works
\newbox\TOCbox
\makeatletter
\etocsetstyle{chapter}
{\sffamily\parskip\z@skip\parindent\z@}
{\allowbreak
\rule{\linewidth}{1pt}\par
\nobreak Chapter \etocnumber. \MakeUppercase{\etocname}\par
\nobreak
\rule[\dimexpr.4\baselineskip-1pt\relax]{\linewidth}{1pt}\par
}
{}
{}
% loop facilities not needed after all
% \usepackage{xinttools}
\def\TOCleftsep{1.25cm}
%\def\TOCrightsep{1cm}
\def\TOCnumwidth{0.75cm}
\def\TOCpnumwidth{0.5cm}
\etocsetstyle {section}
{\leftskip\z@skip\parfillskip\z@skip
\rightskip\TOCpnumwidth\relax
{\Gin@drafttrue\setbox\TOCbox\hbox{\sectocdeco}%
\@tempcnta\ht\TOCbox
\advance\@tempcnta\m@ne
\@tempcntb\baselineskip
\divide\@tempcnta\@tempcntb
\needspace{\@tempcnta\baselineskip}%
\advance\@tempcnta\@ne
\xdef\TOC@shiftedlines{\the\@tempcnta}%
\dimen@\wd\TOCbox
\advance\dimen@\TOCleftsep\relax
\ifdim\dimexpr\ht\TOCbox+\dp\TOCbox=\z@
\gdef\TOC@shiftedlines{0}%
\else
\xdef\TOC@leftskip{\the\dimen@}%
\fi }%
}
{\ifnum\TOC@shiftedlines>\z@
\leftskip\TOC@leftskip\relax
\etociffirst
{\leavevmode\llap{{\raisebox{\dimexpr-\height+\ht\strutbox\relax}
[\ht\strutbox][\z@]{\sectocdeco}}\hspace{\TOCleftsep}}}{}%
\else
\leftskip\TOCnumwidth\relax
\fi
\leavevmode
\llap{\makebox[\TOCnumwidth][l]{\etocnumber}}%
\etocname\nobreak\hfill\rlap{\makebox[\rightskip][r]{\etocpage}}%
\par}
{\edef\TOC@shiftedlines{\the\numexpr\TOC@shiftedlines-\prevgraf}}
{\leftskip\z@skip\rightskip\z@skip\parfillskip\@flushglue
\count@\TOC@shiftedlines\relax
\loop\ifnum\count@>\z@\leavevmode\par\advance\count@\m@ne\repeat}
\makeatother
\newcommand*{\setsectocdeco}[1]%
{\addtocontents{toc}{\def\string\sectocdeco{\protect#1}}}
%\renewcommand{\etocaftertochook}{\thispagestyle{empty}}
\begin{document}
\tableofcontents
\setsectocdeco{\includegraphics[height=2cm]{Pythagore_1}}
\chapter{Foo}
\section{Foo}
\section{This is a section with a long long long long long long long long long long long long long long long long name}
\setsectocdeco{\includegraphics[height=3cm]{Pythagore_2}}
\chapter{Bar}
\section{Foo}
\section{Foofoo}
\section{Foo}
\section{Foofoo}
\section{This is a section with a long long long long long long long long long long long long long long long long name}
\section{Foo}
\section{Foofoo}
\section{Foo}
\section{Foofoo}
% test of needspace
%\addtocontents{toc}{\string\vspace{1.1cm}}
%\setsectocdeco{\includegraphics[height=5cm]{example-image-c}}
% test with empty decor
\setsectocdeco{}
\chapter{FooBar}
\section{Foo}
\section{Foofoo}
\section{Foo}
\section{Foofoo}
\section{Foo}
\section{Foofoo}
\end{document}

etocmight be an alternative totitletoc, see e.g. http://tex.stackexchange.com/a/307507/36296 – samcarter_is_at_topanswers.xyz Oct 18 '16 at 23:40figurethat is just to allow latex to move the figure to another page, for fixed position images just use\includegraphicsdirectly – David Carlisle Oct 18 '16 at 23:42