feat: add isImageFile() static utility method

Adds a static isImageFile() method to CImage that validates if a file
path points to a loadable image by attempting to load it. Returns true
only if the image loads successfully. Memory is freed immediately after
the check via scope block.
This commit is contained in:
y0usaf 2026-01-10 01:25:42 -05:00
parent f114ea3d97
commit 52aa6ef829
2 changed files with 11 additions and 0 deletions

View file

@ -37,6 +37,8 @@ namespace Hyprgraphics {
Hyprutils::Memory::CSharedPointer<CCairoSurface> cairoSurface();
static bool isImageFile(const std::string& path);
private:
std::string lastError, filepath, mime;
Hyprutils::Math::Vector2D m_svgSize;

View file

@ -123,3 +123,12 @@ Hyprutils::Memory::CSharedPointer<CCairoSurface> Hyprgraphics::CImage::cairoSurf
std::string Hyprgraphics::CImage::getMime() {
return mime;
}
bool Hyprgraphics::CImage::isImageFile(const std::string& path) {
bool result;
{
CImage test(path);
result = test.success();
} // test destroyed here, memory freed
return result;
}