mirror of
https://github.com/minetest/minetestmapper.git
synced 2024-11-25 17:03:47 +01:00
Re-add support for outdated libgd
This commit is contained in:
parent
7c71138fec
commit
6af6be4632
13
Image.cpp
13
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)
|
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();
|
const char *f = filename.c_str();
|
||||||
if (gdSupportsFileType(f, 1) == GD_FALSE)
|
if (gdSupportsFileType(f, 1) == GD_FALSE)
|
||||||
throw std::runtime_error("Image format not supported by gd");
|
throw std::runtime_error("Image format not supported by gd");
|
||||||
if (gdImageFile(m_image, f) == GD_FALSE)
|
if (gdImageFile(m_image, f) == GD_FALSE)
|
||||||
throw std::runtime_error("Error saving image");
|
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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user