From c11d2aa6b0e2fd5166231d996943911d77390b91 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 24 Mar 2018 15:37:06 +0100 Subject: [PATCH] Re-add support for outdated libgd --- Image.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Image.cpp b/Image.cpp index b5f0f02..ca40c47 100644 --- a/Image.cpp +++ b/Image.cpp @@ -104,8 +104,19 @@ void Image::drawCircle(int x, int y, int diameter, const Color &c) void Image::save(const std::string &filename) { const char *f = filename.c_str(); +#if (GD_MAJOR_VERSION == 2 && GD_MINOR_VERSION >= 1) || GD_MAJOR_VERSION > 2 if (gdSupportsFileType(f, 1) == GD_FALSE) throw std::runtime_error("Image format not supported by gd"); if (gdImageFile(m_image, f) == GD_FALSE) throw std::runtime_error("Error saving image"); +#else + FILE *file = fopen(f, "wb"); + if(!file) { + std::ostringstream oss; + oss << "Error writing image file: " << std::strerror(errno); + throw std::runtime_error(oss.str()); + } + gdImagePng(m_image, file); + fclose(file); +#endif }