From 52aa6ef829c217587e0fc6c70759bbd37d0273a6 Mon Sep 17 00:00:00 2001 From: y0usaf Date: Sat, 10 Jan 2026 01:25:42 -0500 Subject: [PATCH] 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. --- include/hyprgraphics/image/Image.hpp | 2 ++ src/image/Image.cpp | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/include/hyprgraphics/image/Image.hpp b/include/hyprgraphics/image/Image.hpp index 875dbc9..2fa2902 100644 --- a/include/hyprgraphics/image/Image.hpp +++ b/include/hyprgraphics/image/Image.hpp @@ -37,6 +37,8 @@ namespace Hyprgraphics { Hyprutils::Memory::CSharedPointer cairoSurface(); + static bool isImageFile(const std::string& path); + private: std::string lastError, filepath, mime; Hyprutils::Math::Vector2D m_svgSize; diff --git a/src/image/Image.cpp b/src/image/Image.cpp index 9c2985a..96853f0 100644 --- a/src/image/Image.cpp +++ b/src/image/Image.cpp @@ -123,3 +123,12 @@ Hyprutils::Memory::CSharedPointer 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; +}