Skip to content
Permalink
Browse files

Re-add support for outdated libgd

  • Loading branch information
sfan5 committed Mar 24, 2018
1 parent 7c71138 commit 6af6be4632d25d2632ee7ebd0a8df5487e921609
Showing with 13 additions and 0 deletions.
  1. +13 −0 Image.cpp
@@ -103,9 +103,22 @@ void Image::drawCircle(int x, int y, int diameter, const Color &c)

void Image::save(const std::string &filename)
{
#if (GD_MAJOR_VERSION == 2 && GD_MINOR_VERSION >= 1 && GD_RELEASE_VERSION >= 1) || GD_MAJOR_VERSION > 2
const char *f = filename.c_str();
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
if (filename.compare(filename.length() - 4, 4, ".png") != 0)
throw std::runtime_error("Only PNG is supported");
FILE *f = fopen(filename.c_str(), "wb");
if (!f) {
std::ostringstream oss;
oss << "Error opening image file: " << std::strerror(errno);
throw std::runtime_error(oss.str());
}
gdImagePng(m_image, f);
fclose(f);
#endif
}

0 comments on commit 6af6be4

Please sign in to comment.