Skip to content

Commit

Permalink
Re-add support for outdated libgd
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Mar 24, 2018
1 parent 7c71138 commit c11d2aa
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Image.cpp
Expand Up @@ -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
}

0 comments on commit c11d2aa

Please sign in to comment.