IsImageUrlDotNet 2.0.0
dotnet add package IsImageUrlDotNet --version 2.0.0
NuGet\Install-Package IsImageUrlDotNet -Version 2.0.0
<PackageReference Include="IsImageUrlDotNet" Version="2.0.0" />
<PackageVersion Include="IsImageUrlDotNet" Version="2.0.0" />
<PackageReference Include="IsImageUrlDotNet" />
paket add IsImageUrlDotNet --version 2.0.0
#r "nuget: IsImageUrlDotNet, 2.0.0"
#:package IsImageUrlDotNet@2.0.0
#addin nuget:?package=IsImageUrlDotNet&version=2.0.0
#tool nuget:?package=IsImageUrlDotNet&version=2.0.0
IsImageUrlDotNet
Tells whether a URL points at an image. Ask offline, from the extension of the URL's path, or ask the server for the media type it answers with. Written in F#; works the same from C# and F#. Builds for net10.0, net462 and netstandard2.0, so it runs on .NET Framework 4.6.2 and later, on every current .NET and on other .NET Standard 2.0 platforms, on Windows, macOS and Linux.
dotnet add package IsImageUrlDotNet
Usage
C#:
using IsImageUrlDotNet;
"https://example.com/photos/cat.PNG?w=200".HasImageExtension(); // true, offline
"https://example.com/report.pdf".HasImageExtension(); // false
bool isImage = await "https://example.com/avatar".IsImageUrlAsync(); // asks the server
bool viaMine = await ImageUrl.IsImageUrlAsync(url, myHttpClient, cancellationToken);
F#:
open IsImageUrlDotNet
ImageUrl.HasImageExtension "https://example.com/photos/cat.PNG?w=200" // true
let! isImage = ImageUrl.IsImageUrlAsync("https://example.com/avatar") // inside task { }
API
| Member | What it does |
|---|---|
ImageUrl.HasImageExtension(url) |
True when the path of the URL ends in an image extension (ImageUrl.ImageExtensions), without regard to case or culture. The query and fragment are ignored. Offline; never throws. False for null, blank, and any string with a scheme other than http or https (file:, ftp:, data:, C:\...). A protocol-relative //cdn.example/a.png is read as http; anything else, such as photos/cat.png?w=1 or /images/a.png, is read as a path, with the same answer on every OS. |
ImageUrl.IsImageUrlAsync(url) and overloads with an HttpClient and a CancellationToken |
For http and https URLs only: true when the extension is an image one; otherwise sends a GET, reads only the response headers, and answers true for a 2xx status with an image/* media type. It follows up to 10 redirects itself, http and https only and never from https to http; a redirect anywhere else answers false. False for other schemes, malformed URLs, other statuses and other media types. Throws HttpRequestException when the server cannot be reached, TaskCanceledException on timeout or cancellation, and ArgumentNullException for a null HttpClient. Without a client of yours it uses one shared HttpClient with a 10-second timeout and a User-Agent naming this package. |
ImageUrl.ImageExtensions |
The 16 extensions HasImageExtension accepts: png, jpg, jpeg, gif, raw, bmp, svg, psd, webp, avif, apng, ico, tif, tiff, heic, heif. |
IsImageUrlDotNetLib.IsImageUrl(url), url.IsImageUrl() |
Obsolete; kept exactly as 1.0.2 had it. See below. |
IsImageUrlDotNetLib.ImageFileExtensions, NonImageFileExtensions |
1.0.2's two F# lists, eight values each, unchanged. |
Moving from 1.x
url.IsImageUrl() still compiles and gives 1.0.2's answers on each runtime, bugs included. The build warns that it is obsolete. Every case recorded from the published 1.0.2 (tests/Golden/) is checked on every build. Those answers include:
- It decides by the text after the last dot of the whole string, so
a.png?size=1sends a request. - It throws for many inputs it cannot decide (
"a","x.webp", unknown schemes, every 4xx and 5xx answer). - It matches the Content-Type as a case-sensitive substring (
IMAGE/PNGis false,application/x-imagefileis true). - It reads local files for
file:URLs, and on Linux and macOS for rooted paths. - It follows redirects to any host and waits up to 100 seconds.
- It depends on the current culture: under Turkish,
x.GIFthrows.
Use HasImageExtension where 1.x was used as an offline check, and IsImageUrlAsync where it made a request. The package now declares its FSharp.Core dependency (6.0.7 or later); 1.x needed FSharp.Core without saying so.
Limits and what this package is not
- The extension check is a guess from the name. The server check trusts the server's
Content-Typeheader and never looks at the bytes. IsImageUrlAsyncfetches whatever http or https URL it is given, following redirects. That is not protection against server-side request forgery. A service that checks URLs from untrusted users should pass its ownHttpClientwhose handler refuses private and loopback addresses and hasAllowAutoRedirect = false. A handler that follows redirects applies its own rules: on .NET 5 and later it follows aLocationwith another scheme, such asftp://host:21/, as if it were http. With automatic redirects off,IsImageUrlAsyncfollows them itself under the rules above. Never pass such URLs to the obsoleteIsImageUrl, which also reads local files.- From C#,
url.IsImageUrlAsync(default)does not compile: it is ambiguous between theHttpClientand theCancellationTokenoverloads. PassCancellationToken.Noneor a client. - It does not download images, validate them, or read their dimensions.
Contributing and support
Issues and pull requests are welcome. Security problems: see SECURITY.md. Changes are listed in CHANGELOG.md. MIT licence.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- FSharp.Core (>= 6.0.7)
-
.NETStandard 2.0
- FSharp.Core (>= 6.0.7)
-
net10.0
- FSharp.Core (>= 6.0.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 2.0.0 | 101 | 9/27/2026 | |
| 2.0.0-beta.1 | 50 | 9/27/2026 | |
| 1.0.2 | 2,396 | 6/5/2016 | |
| 1.0.0 | 2,159 | 5/30/2016 |