title: Error when attempting to save image with CImg
body: <p>I am attempting to generate map tiles from a world generator that I have adapted using libnoise. Using the libnoise saving methods work fine, but when attempting to scale and crop images using CImg, i get the following error:</p>
  
  <pre><code>[CImg] *** CImgIOException *** cimg::fopen(): Failed to open file '~/tiles/0/0/0.bmp' with mode 'wb'.
  </code></pre>
  
  <p>Relevant method:</p>
  
  <pre><code>void makeTile(CImg&lt;unsigned char&gt; image, int zoom, int x, int y, int depth, int argc, char* argv[]) {
      std::string directoryBase = "mkdir -p ~/tiles/" + boost::lexical_cast&lt;std::string&gt;(zoom);
      std::string directory = directoryBase + "/" + boost::lexical_cast&lt;std::string&gt;(x);
      std::string filename = "~/tiles/" + boost::lexical_cast&lt;std::string&gt;(zoom) + "/" + boost::lexical_cast&lt;std::string&gt;(x) + "/" + boost::lexical_cast&lt;std::string&gt;(y) + ".bmp";
  
      const char* file_o = cimg_option("-o", filename.c_str(), "Output file");
      system(directoryBase.c_str());
      system(directory.c_str());
      std::cout &lt;&lt; "Made required dirs\n";
      CImg&lt;unsigned char&gt; imageClone = image.get_resize(256, 256, -100, -100, 1);
  
      std::cout &lt;&lt; "scaled image\n";
      imageClone.save(file_o);
  
      if (depth &gt; 0) {
          int smallX = x * 2;
          int smallY = y * 2;
          makeTile(image.get_crop(0, 0, image._width / 2, image._height / 2), zoom + 1, smallX, smallY, depth - 1, argc, argv);
          makeTile(image.get_crop(image._width / 2, 0, image._width, image._height / 2), zoom + 1, smallX + 1, smallY, depth - 1, argc, argv);
          makeTile(image.get_crop(0, image._height / 2, image._width / 2, image._height), zoom + 1, smallX, smallY + 1, depth - 1, argc, argv);
          makeTile(image.get_crop(image._width / 2, image._height / 2, image._width, image._height), zoom + 1, smallX + 1, smallY + 1, depth - 1, argc, argv);
      }
  }
  </code></pre>
  
  <p>The image sent to this method on the first loop is the generated map from libnoise and loaded using CImg.</p>