title: Bash - change image urls to base64 in html
body: <p>28I tried to make a script that's converting images source from normal links to base64 encoding in html files.
  But there is a problem: sometimes, sed tells me</p>
  
  <blockquote>
    <p>script.sh: line 25: /bin/sed: Argument list too long</p>
  </blockquote>
  
  <p>This is the code:</p>
  
  <pre><code>#!/bin/bash
  # usage: ./script.sh file.html
  
  
  mkdir images_temp
  
  for i in `sed -n '/&lt;img/s/.*src="\([^"]*\)".*/\1/p' $1`;
  
      do echo "######### download the image";
      wget -P images_temp/ $i;
  
      #echo "######### convert the image for size saving";
      #convert -quality 70 `echo ${i##*/}` `echo ${i##*/}`.temp;
  
      #echo "######### rename temp image";
      #rm `echo ${i##*/}` &amp;&amp; mv `echo ${i##*/}`.temp `echo ${i##*/}`;
  
      echo "######### encode in base64";
      k="`echo "data:image/png;base64,"`$(base64 -w 0 images_temp/`echo ${i##*/}`)";
  
      echo "######### deletion of images_temp pictures";
      rm images_temp/*;
  
      echo "######### remplace string in html";
      sed -e "s|$i|$k|" $1 &gt; temp.html;
  
      echo "######### remplace final file";
      rm -rf $1 &amp;&amp; mv temp.html $1;
  
      sleep 5;
  done;
  </code></pre>
  
  <p>I think the $k argument is too long for sed when the image is bigger than ~128ko; sed can't process it.</p>
  
  <p>How do I make it work ?</p>
  
  <p>Thank you in advance !</p>
  
  <p>PS1: and sorry for the very very ugly code</p>
  
  <p>PS2: or how do I do that in python ? PHP ? I'm open !</p>