Yalantis/uCrop · error · CImgIOException

cimg::load_network(): Failed to load file '%s' with external

Error message

cimg::load_network(): Failed to load file '%s' with external commands 'wget', 'curl', or 'powershell'.

What it means

cimg::load_network() downloads a remote URL to a local file by shelling out to external tools (wget/curl on Linux/macOS, powershell on Windows). After running all configured commands it checks the downloaded file size; if the file is empty or missing (cimg::fsize <= 0) it throws CImgIOException because no external command succeeded in fetching the URL.

Source

Thrown at ucrop/src/main/jni/CImg.h:70157

        cimg::system(command,cimg::powershell_path());
      }
#endif

      if (cimg::fsize(filename_local)<=0) { // Try with 'wget' otherwise
        if (timeout) cimg_snprintf(s_timeout.assign(64),64,"-T %u ",timeout);
        else s_timeout.assign(1,1,1,1,0);
        if (referer) cimg_snprintf(s_referer.assign(1024),1024,"--referer=%s ",referer);
        else s_referer.assign(1,1,1,1,0);
        if (user_agent) cimg_snprintf(s_user_agent.assign(1024),1024,"--user-agent=\"%s\" ",user_agent);
        else s_user_agent.assign(1,1,1,1,0);
        cimg_snprintf(command,command._width,
                      "\"%s\" --max-redirect=20 %s%s%s-q -r -l 0 --no-cache -O \"%s\" \"%s\"",
                      cimg::wget_path(),s_timeout._data,s_referer._data,s_user_agent._data,filename_local,
                      CImg<char>::string(url)._system_strescape().data());
        cimg::system(command,cimg::wget_path());

        if (cimg::fsize(filename_local)<=0)
          throw CImgIOException("cimg::load_network(): Failed to load file '%s' with external commands "
#if cimg_OS==2
                                "'wget', 'curl', or 'powershell'.",url);
#else
                                "'wget' or 'curl'.",url);
#endif

        // Try gunzip it.
        cimg_snprintf(command,command._width,"%s.gz",filename_local);
        std::rename(filename_local,command);
        cimg_snprintf(command,command._width,"\"%s\" --quiet \"%s.gz\"",
                      gunzip_path(),filename_local);
        cimg::system(command,gunzip_path());
        if (!cimg::is_file(filename_local)) {
          cimg_snprintf(command,command._width,"%s.gz",filename_local);
          std::rename(command,filename_local);
        }
      }

View on GitHub (pinned to f788b534b4)

Solutions

  1. Install wget or curl (or on Windows, verify powershell is available) and ensure it is on PATH, or set the correct tool path via cimg::wget_path(...)/cimg::curl_path(...) before loading.
  2. Open the URL in a browser or run `curl -I <url>` manually to confirm the URL is valid, reachable, and returns 200.
  3. Download the file manually (browser/curl) and load the local file with CImg<T>::load() instead of load_network().
  4. Check network/proxy/VPN settings and certificate issues; increase the timeout if the request was cut off.

Example fix

// before
CImg<unsigned char> img;
img.load_network("https://example.com/image.jpg"); // throws if curl/wgit missing or URL unreachable
// after
if (std::system("command -v curl >/dev/null 2>&1") == 0) {
  try {
    img.load_network("https://example.com/image.jpg");
  } catch (CImgIOException&) {
    img.load("fallback_image.jpg"); // local fallback
  }
} else {
  img.load("fallback_image.jpg");
}
Defensive patterns

Strategy: fallback

Validate before calling

// Check an external downloader exists and the URL is reachable before load_network()
bool canDownload(const char* url) {
  if (std::system("command -v wget >/dev/null 2>&1") != 0 &&
      std::system("command -v curl >/dev/null 2>&1") != 0) return false;
  std::string cmd = std::string("curl -fsSI --max-time 5 ") + url + " >/dev/null 2>&1";
  return std::system(cmd.c_str()) == 0; // HEAD request succeeds (2xx)
}
if (!canDownload("https://example.com/image.jpg")) { /* use local file / skip */ }

Try / catch

try {
  img.load_network(url);
} catch (CImgIOException& e) {
  std::cerr << "Network load failed: " << e.what() << "\n";
  img.load(local_fallback_path); // or skip with a default image
}

Prevention

When it happens

Trigger: Calling CImg<float>::load()/.load_network() (or load_other/load_magick fallbacks) on an http/https/ftp URL when: no wget/curl/powershell binary exists on PATH or their paths (cimg::wget_path/curl_path) are wrong; the URL is malformed, 404, or the server is unreachable; a proxy/firewall blocks the request; the timeout (-timeout-m 5) or max-redirect limit is exceeded; or TLS certificate verification fails.

Common situations: Docker/container or CI images without curl/wget installed; offline/air-gapped machines where CImg tries to fetch example images or documentation assets; VPN/proxy environments blocking outbound requests; wrong cimg::path definitions for the external tools; server-side 4xx/5xx responses.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/9404a03e334166d6. Report an issue: GitHub.